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 final SourceInformationStrategy sourceInformationFactory; | 10 final SourceInformationStrategy sourceInformationFactory; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 SsaVariableAllocator allocator = new SsaVariableAllocator( | 240 SsaVariableAllocator allocator = new SsaVariableAllocator( |
241 compiler, | 241 compiler, |
242 intervalBuilder.liveInstructions, | 242 intervalBuilder.liveInstructions, |
243 intervalBuilder.liveIntervals, | 243 intervalBuilder.liveIntervals, |
244 generateAtUseSite); | 244 generateAtUseSite); |
245 allocator.visitGraph(graph); | 245 allocator.visitGraph(graph); |
246 variableNames = allocator.names; | 246 variableNames = allocator.names; |
247 shouldGroupVarDeclarations = allocator.names.numberOfVariables > 1; | 247 shouldGroupVarDeclarations = allocator.names.numberOfVariables > 1; |
248 } | 248 } |
249 | 249 |
250 void handleDelayedVariableDeclarations() { | 250 void handleDelayedVariableDeclarations(SourceInformation sourceInformation) { |
251 // If we have only one variable declaration and the first statement is an | 251 // If we have only one variable declaration and the first statement is an |
252 // assignment to that variable then we can merge the two. We count the | 252 // assignment to that variable then we can merge the two. We count the |
253 // number of variables in the variable allocator to try to avoid this issue, | 253 // number of variables in the variable allocator to try to avoid this issue, |
254 // but it sometimes happens that the variable allocator introduces a | 254 // but it sometimes happens that the variable allocator introduces a |
255 // temporary variable that it later eliminates. | 255 // temporary variable that it later eliminates. |
256 if (!collectedVariableDeclarations.isEmpty) { | 256 if (!collectedVariableDeclarations.isEmpty) { |
257 if (collectedVariableDeclarations.length == 1 && | 257 if (collectedVariableDeclarations.length == 1 && |
258 currentContainer.statements.length >= 1 && | 258 currentContainer.statements.length >= 1 && |
259 currentContainer.statements[0] is js.ExpressionStatement) { | 259 currentContainer.statements[0] is js.ExpressionStatement) { |
260 String name = collectedVariableDeclarations.first; | 260 String name = collectedVariableDeclarations.first; |
261 js.ExpressionStatement statement = currentContainer.statements[0]; | 261 js.ExpressionStatement statement = currentContainer.statements[0]; |
262 if (statement.expression is js.Assignment) { | 262 if (statement.expression is js.Assignment) { |
263 js.Assignment assignment = statement.expression; | 263 js.Assignment assignment = statement.expression; |
264 if (!assignment.isCompound && | 264 if (!assignment.isCompound && |
265 assignment.leftHandSide is js.VariableReference) { | 265 assignment.leftHandSide is js.VariableReference) { |
266 js.VariableReference variableReference = assignment.leftHandSide; | 266 js.VariableReference variableReference = assignment.leftHandSide; |
267 if (variableReference.name == name) { | 267 if (variableReference.name == name) { |
268 js.VariableDeclaration decl = new js.VariableDeclaration(name); | 268 js.VariableDeclaration decl = new js.VariableDeclaration(name); |
269 js.VariableInitialization initialization = | 269 js.VariableInitialization initialization = |
270 new js.VariableInitialization(decl, assignment.value); | 270 new js.VariableInitialization(decl, assignment.value); |
271 currentContainer.statements[0] = new js.ExpressionStatement( | 271 currentContainer.statements[0] = new js.ExpressionStatement( |
272 new js.VariableDeclarationList([initialization])); | 272 new js.VariableDeclarationList([initialization])) |
| 273 .withSourceInformation(sourceInformation); |
273 return; | 274 return; |
274 } | 275 } |
275 } | 276 } |
276 } | 277 } |
277 } | 278 } |
278 // If we can't merge the declaration with the first assignment then we | 279 // If we can't merge the declaration with the first assignment then we |
279 // just do it with a new var z,y,x; statement. | 280 // just do it with a new var z,y,x; statement. |
280 List<js.VariableInitialization> declarations = | 281 List<js.VariableInitialization> declarations = |
281 <js.VariableInitialization>[]; | 282 <js.VariableInitialization>[]; |
282 collectedVariableDeclarations.forEach((String name) { | 283 collectedVariableDeclarations.forEach((String name) { |
283 declarations.add(new js.VariableInitialization( | 284 declarations.add(new js.VariableInitialization( |
284 new js.VariableDeclaration(name), null)); | 285 new js.VariableDeclaration(name), null)); |
285 }); | 286 }); |
286 var declarationList = new js.VariableDeclarationList(declarations); | 287 var declarationList = new js.VariableDeclarationList(declarations) |
| 288 .withSourceInformation(sourceInformation);; |
287 insertStatementAtStart(new js.ExpressionStatement(declarationList)); | 289 insertStatementAtStart(new js.ExpressionStatement(declarationList)); |
288 } | 290 } |
289 } | 291 } |
290 | 292 |
291 visitGraph(HGraph graph) { | 293 visitGraph(HGraph graph) { |
292 preGenerateMethod(graph); | 294 preGenerateMethod(graph); |
293 currentGraph = graph; | 295 currentGraph = graph; |
294 subGraph = new SubGraph(graph.entry, graph.exit); | 296 subGraph = new SubGraph(graph.entry, graph.exit); |
295 visitBasicBlock(graph.entry); | 297 visitBasicBlock(graph.entry); |
296 handleDelayedVariableDeclarations(); | 298 handleDelayedVariableDeclarations(graph.sourceInformation); |
297 } | 299 } |
298 | 300 |
299 void visitSubGraph(SubGraph newSubGraph) { | 301 void visitSubGraph(SubGraph newSubGraph) { |
300 SubGraph oldSubGraph = subGraph; | 302 SubGraph oldSubGraph = subGraph; |
301 subGraph = newSubGraph; | 303 subGraph = newSubGraph; |
302 visitBasicBlock(subGraph.start); | 304 visitBasicBlock(subGraph.start); |
303 subGraph = oldSubGraph; | 305 subGraph = oldSubGraph; |
304 } | 306 } |
305 | 307 |
306 /** | 308 /** |
(...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2911 new StaticUse.staticInvoke(helper, | 2913 new StaticUse.staticInvoke(helper, |
2912 new CallStructure.unnamed(argumentCount))); | 2914 new CallStructure.unnamed(argumentCount))); |
2913 return backend.emitter.staticFunctionAccess(helper); | 2915 return backend.emitter.staticFunctionAccess(helper); |
2914 } | 2916 } |
2915 | 2917 |
2916 @override | 2918 @override |
2917 void visitRef(HRef node) { | 2919 void visitRef(HRef node) { |
2918 visit(node.value); | 2920 visit(node.value); |
2919 } | 2921 } |
2920 } | 2922 } |
OLD | NEW |