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 2171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2182 } else { | 2182 } else { |
2183 use(node.checkedInput, expectedPrecedence); | 2183 use(node.checkedInput, expectedPrecedence); |
2184 } | 2184 } |
2185 } | 2185 } |
2186 } | 2186 } |
2187 | 2187 |
2188 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2188 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
2189 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) | 2189 SsaOptimizedCodeGenerator(backend, work, parameters, parameterNames) |
2190 : super(backend, work, parameters, parameterNames); | 2190 : super(backend, work, parameters, parameterNames); |
2191 | 2191 |
| 2192 int maxBailoutParameters; |
| 2193 |
2192 void beginGraph(HGraph graph) {} | 2194 void beginGraph(HGraph graph) {} |
2193 void endGraph(HGraph graph) {} | 2195 void endGraph(HGraph graph) {} |
2194 | 2196 |
2195 void bailout(HTypeGuard guard, String reason) { | 2197 void bailout(HTypeGuard guard, String reason) { |
| 2198 if (maxBailoutParameters === null) { |
| 2199 maxBailoutParameters = 0; |
| 2200 work.guards.forEach((HTypeGuard guard) { |
| 2201 int inputLength = guard.inputs.length; |
| 2202 if (inputLength > maxBailoutParameters) { |
| 2203 maxBailoutParameters = inputLength; |
| 2204 } |
| 2205 }); |
| 2206 } |
2196 HInstruction input = guard.guarded; | 2207 HInstruction input = guard.guarded; |
2197 Namer namer = compiler.namer; | 2208 Namer namer = compiler.namer; |
2198 Element element = work.element; | 2209 Element element = work.element; |
2199 buffer.add('return '); | 2210 buffer.add('return '); |
2200 if (element.isInstanceMember()) { | 2211 if (element.isInstanceMember()) { |
2201 // TODO(ngeoffray): This does not work in case we come from a | 2212 // TODO(ngeoffray): This does not work in case we come from a |
2202 // super call. We must make bailout names unique. | 2213 // super call. We must make bailout names unique. |
2203 buffer.add('this.${namer.getBailoutName(element)}'); | 2214 buffer.add('this.${namer.getBailoutName(element)}'); |
2204 } else { | 2215 } else { |
2205 buffer.add(namer.isolateBailoutAccess(element)); | 2216 buffer.add(namer.isolateBailoutAccess(element)); |
2206 } | 2217 } |
2207 int parametersCount = parameterNames.length; | 2218 int parametersCount = parameterNames.length; |
2208 buffer.add('($parameters'); | 2219 buffer.add('($parameters'); |
2209 if (parametersCount != 0) buffer.add(', '); | 2220 if (parametersCount != 0) buffer.add(', '); |
2210 if (guard.guarded is !HParameterValue) { | 2221 buffer.add('${guard.state}'); |
2211 buffer.add('${guard.state}'); | 2222 // TODO(ngeoffray): try to put a variable at a deterministic |
2212 bool first = true; | 2223 // location, so that multiple bailout calls put the variable at |
2213 // TODO(ngeoffray): if the bailout method takes more arguments, | 2224 // the same parameter index. |
2214 // fill the remaining arguments with undefined. | 2225 int i = 0; |
2215 // TODO(ngeoffray): try to put a variable at a deterministic | 2226 for (; i < guard.inputs.length; i++) { |
2216 // location, so that multiple bailout calls put the variable at | 2227 buffer.add(', '); |
2217 // the same parameter index. | 2228 use(guard.inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); |
2218 for (int i = 0; i < guard.inputs.length; i++) { | 2229 } |
2219 buffer.add(', '); | 2230 // Make sure we call the bailout method with the number of |
2220 use(guard.inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); | 2231 // arguments it expects. This avoids having the underlying |
2221 } | 2232 // JS engine fill them in for us. |
2222 } else { | 2233 for (; i < maxBailoutParameters; i++) { |
2223 assert(guard.guarded is HParameterValue); | 2234 buffer.add(', 0'); |
2224 buffer.add(' 0'); | |
2225 } | 2235 } |
2226 buffer.add(')'); | 2236 buffer.add(')'); |
2227 } | 2237 } |
2228 | 2238 |
2229 void visitTypeGuard(HTypeGuard node) { | 2239 void visitTypeGuard(HTypeGuard node) { |
2230 addIndentation(); | 2240 addIndentation(); |
2231 HInstruction input = node.guarded; | 2241 HInstruction input = node.guarded; |
2232 if (node.isInteger()) { | 2242 if (node.isInteger()) { |
2233 buffer.add('if ('); | 2243 buffer.add('if ('); |
2234 checkInt(input, '!=='); | 2244 checkInt(input, '!=='); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 startBailoutSwitch(); | 2581 startBailoutSwitch(); |
2572 } | 2582 } |
2573 } | 2583 } |
2574 | 2584 |
2575 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2585 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
2576 if (labeledBlockInfo.body.start.hasGuards()) { | 2586 if (labeledBlockInfo.body.start.hasGuards()) { |
2577 endBailoutSwitch(); | 2587 endBailoutSwitch(); |
2578 } | 2588 } |
2579 } | 2589 } |
2580 } | 2590 } |
OLD | NEW |