| 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 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); | 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA code generator'; | 7 String get name() => 'SSA code generator'; |
| 8 | 8 |
| 9 String generate(WorkItem work, HGraph graph) { | 9 String generate(WorkItem work, HGraph graph) { |
| 10 return measure(() { | 10 return measure(() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 void preGenerateMethod(HGraph graph) { | 26 void preGenerateMethod(HGraph graph) { |
| 27 if (GENERATE_SSA_TRACE) { | 27 if (GENERATE_SSA_TRACE) { |
| 28 new HTracer.singleton().traceGraph("codegen", graph); | 28 new HTracer.singleton().traceGraph("codegen", graph); |
| 29 } | 29 } |
| 30 new SsaInstructionMerger().visitGraph(graph); | 30 new SsaInstructionMerger().visitGraph(graph); |
| 31 // Replace the results of check instructions with the | 31 // Replace the results of check instructions with the |
| 32 // original value, if the result is used. This is safe now, | 32 // original value, if the result is used. This is safe now, |
| 33 // since we don't do code motion after this point. | 33 // since we don't do code motion after this point. |
| 34 new SsaCheckInstructionUnuser().visitGraph(graph); | 34 new SsaCheckInstructionUnuser().visitGraph(graph); |
| 35 new SsaConditionMerger().visitGraph(graph); | 35 new SsaConditionMerger().visitGraph(graph); |
| 36 // JavaScript only supports characters in the BMP. |
| 36 new SsaPhiEliminator().visitGraph(graph); | 37 new SsaPhiEliminator().visitGraph(graph); |
| 37 if (GENERATE_SSA_TRACE) { | 38 if (GENERATE_SSA_TRACE) { |
| 38 new HTracer.singleton().traceGraph("no-phi", graph); | 39 new HTracer.singleton().traceGraph("no-phi", graph); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 String generateMethod(Map<Element, String> parameterNames, | 43 String generateMethod(Map<Element, String> parameterNames, |
| 43 WorkItem work, | 44 WorkItem work, |
| 44 HGraph graph) { | 45 HGraph graph) { |
| 45 preGenerateMethod(graph); | 46 preGenerateMethod(graph); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 buffer.add('new $jsClassReference('); | 454 buffer.add('new $jsClassReference('); |
| 454 // We can't use 'visitArguments', since our arguments start at input[0]. | 455 // We can't use 'visitArguments', since our arguments start at input[0]. |
| 455 List<HInstruction> inputs = node.inputs; | 456 List<HInstruction> inputs = node.inputs; |
| 456 for (int i = 0; i < inputs.length; i++) { | 457 for (int i = 0; i < inputs.length; i++) { |
| 457 if (i != 0) buffer.add(', '); | 458 if (i != 0) buffer.add(', '); |
| 458 use(inputs[i]); | 459 use(inputs[i]); |
| 459 } | 460 } |
| 460 buffer.add(')'); | 461 buffer.add(')'); |
| 461 } | 462 } |
| 462 | 463 |
| 463 static String makeStringLiteral(SourceString literal) { | |
| 464 // TODO(lrn): Escape string content. | |
| 465 return literal.toString(); | |
| 466 } | |
| 467 | |
| 468 visitLiteral(HLiteral node) { | 464 visitLiteral(HLiteral node) { |
| 469 if (node.isLiteralNull()) { | 465 if (node.isLiteralNull()) { |
| 470 buffer.add("(void 0)"); | 466 buffer.add("(void 0)"); |
| 471 } else if (node.value is num && node.value < 0) { | 467 } else if (node.value is num && node.value < 0) { |
| 472 buffer.add('(${node.value})'); | 468 buffer.add('(${node.value})'); |
| 473 } else if (node.isLiteralString()) { | 469 } else if (node.isLiteralString()) { |
| 474 QuotedString string = node.value; | 470 QuotedString string = node.value; |
| 475 string.printOn(buffer); | 471 String quote = string.quoteChar; |
| 472 buffer.add(quote); |
| 473 string.writeEscaped(buffer, string.quoteCharCode, |
| 474 (String reason) { |
| 475 compiler.cancel(reason, instruction: node); |
| 476 }); |
| 477 buffer.add(quote); |
| 476 } else { | 478 } else { |
| 477 buffer.add(node.value); | 479 buffer.add(node.value); |
| 478 } | 480 } |
| 479 } | 481 } |
| 480 | 482 |
| 481 visitLoopBranch(HLoopBranch node) { | 483 visitLoopBranch(HLoopBranch node) { |
| 482 HBasicBlock branchBlock = currentBlock; | 484 HBasicBlock branchBlock = currentBlock; |
| 483 buffer.add('if (!('); | 485 buffer.add('if (!('); |
| 484 use(node.inputs[0]); | 486 use(node.inputs[0]); |
| 485 buffer.add(')) break;\n'); | 487 buffer.add(')) break;\n'); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 : super(compiler, work, buffer, parameters, parameterNames); | 765 : super(compiler, work, buffer, parameters, parameterNames); |
| 764 | 766 |
| 765 void visitTypeGuard(HTypeGuard guard) { | 767 void visitTypeGuard(HTypeGuard guard) { |
| 766 compiler.internalError('Type guard in an unoptimized method'); | 768 compiler.internalError('Type guard in an unoptimized method'); |
| 767 } | 769 } |
| 768 | 770 |
| 769 visitBailoutTarget(HBailoutTarget node) { | 771 visitBailoutTarget(HBailoutTarget node) { |
| 770 buffer.add('// Bailout target ${node.state}'); | 772 buffer.add('// Bailout target ${node.state}'); |
| 771 } | 773 } |
| 772 } | 774 } |
| OLD | NEW |