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