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 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 new SsaOptimizedCodeGenerator(backend, work); | 58 new SsaOptimizedCodeGenerator(backend, work); |
59 codegen.visitGraph(graph); | 59 codegen.visitGraph(graph); |
60 js.Block body = codegen.body; | 60 js.Block body = codegen.body; |
61 js.Fun fun = new js.Fun(codegen.parameters, body); | 61 js.Fun fun = new js.Fun(codegen.parameters, body); |
62 return prettyPrint(fun); | 62 return prettyPrint(fun); |
63 }); | 63 }); |
64 } | 64 } |
65 | 65 |
66 CodeBuffer generateMethod(WorkItem work, HGraph graph) { | 66 CodeBuffer generateMethod(WorkItem work, HGraph graph) { |
67 return measure(() { | 67 return measure(() { |
68 JavaScriptItemCompilationContext context = work.compilationContext; | |
69 HTypeMap types = context.types; | |
70 graph.exit.predecessors.forEach((block) { | |
71 assert(block.last is HGoto || block.last is HReturn); | |
72 if (block.last is HReturn) { | |
73 backend.registerReturnType(work.element, types[block.last.inputs[0]]); | |
74 } else { | |
75 backend.registerReturnType(work.element, HType.NULL); | |
76 } | |
77 }); | |
78 compiler.tracer.traceGraph("codegen", graph); | 68 compiler.tracer.traceGraph("codegen", graph); |
79 SsaOptimizedCodeGenerator codegen = | 69 SsaOptimizedCodeGenerator codegen = |
80 new SsaOptimizedCodeGenerator(backend, work); | 70 new SsaOptimizedCodeGenerator(backend, work); |
81 codegen.visitGraph(graph); | 71 codegen.visitGraph(graph); |
82 | 72 |
83 FunctionElement element = work.element; | 73 FunctionElement element = work.element; |
84 js.Block body; | 74 js.Block body; |
85 ClassElement enclosingClass = element.getEnclosingClass(); | 75 ClassElement enclosingClass = element.getEnclosingClass(); |
86 bool allowVariableMinification; | 76 bool allowVariableMinification; |
87 if (element.isInstanceMember() | 77 if (element.isInstanceMember() |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 intervalBuilder.visitGraph(graph); | 365 intervalBuilder.visitGraph(graph); |
376 SsaVariableAllocator allocator = new SsaVariableAllocator( | 366 SsaVariableAllocator allocator = new SsaVariableAllocator( |
377 compiler, | 367 compiler, |
378 intervalBuilder.liveInstructions, | 368 intervalBuilder.liveInstructions, |
379 intervalBuilder.liveIntervals, | 369 intervalBuilder.liveIntervals, |
380 generateAtUseSite, | 370 generateAtUseSite, |
381 parameterNames); | 371 parameterNames); |
382 allocator.visitGraph(graph); | 372 allocator.visitGraph(graph); |
383 variableNames = allocator.names; | 373 variableNames = allocator.names; |
384 shouldGroupVarDeclarations = allocator.names.numberOfVariables > 1; | 374 shouldGroupVarDeclarations = allocator.names.numberOfVariables > 1; |
| 375 |
| 376 // Register return types to the backend. |
| 377 graph.exit.predecessors.forEach((HBasicBlock block) { |
| 378 HInstruction last = block.last; |
| 379 assert(last is HGoto || last is HReturn); |
| 380 if (last is HReturn) { |
| 381 backend.registerReturnType(work.element, types[last.inputs[0]]); |
| 382 } else { |
| 383 backend.registerReturnType(work.element, HType.NULL); |
| 384 } |
| 385 }); |
385 } | 386 } |
386 | 387 |
387 void handleDelayedVariableDeclarations() { | 388 void handleDelayedVariableDeclarations() { |
388 // If we have only one variable declaration and the first statement is an | 389 // If we have only one variable declaration and the first statement is an |
389 // assignment to that variable then we can merge the two. We count the | 390 // assignment to that variable then we can merge the two. We count the |
390 // number of variables in the variable allocator to try to avoid this issue, | 391 // number of variables in the variable allocator to try to avoid this issue, |
391 // but it sometimes happens that the variable allocator introduces a | 392 // but it sometimes happens that the variable allocator introduces a |
392 // temporary variable that it later eliminates. | 393 // temporary variable that it later eliminates. |
393 if (!collectedVariableDeclarations.isEmpty) { | 394 if (!collectedVariableDeclarations.isEmpty) { |
394 if (collectedVariableDeclarations.length == 1 && | 395 if (collectedVariableDeclarations.length == 1 && |
(...skipping 2709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3104 if (leftType.canBeNull() && rightType.canBeNull()) { | 3105 if (leftType.canBeNull() && rightType.canBeNull()) { |
3105 if (left.isConstantNull() || right.isConstantNull() || | 3106 if (left.isConstantNull() || right.isConstantNull() || |
3106 (leftType.isPrimitive() && leftType == rightType)) { | 3107 (leftType.isPrimitive() && leftType == rightType)) { |
3107 return '=='; | 3108 return '=='; |
3108 } | 3109 } |
3109 return null; | 3110 return null; |
3110 } else { | 3111 } else { |
3111 return '==='; | 3112 return '==='; |
3112 } | 3113 } |
3113 } | 3114 } |
OLD | NEW |