| 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 494 |
| 495 // Check that the operation is one of +, *, - or /. Record whether | 495 // Check that the operation is one of +, *, - or /. Record whether |
| 496 // or not the operation is commutative. | 496 // or not the operation is commutative. |
| 497 var isCommutative = false; | 497 var isCommutative = false; |
| 498 if (instruction is HAdd || instruction is HMultiply) { | 498 if (instruction is HAdd || instruction is HMultiply) { |
| 499 isCommutative = true; | 499 isCommutative = true; |
| 500 } else if (instruction is !HSubtract && instruction is !HDivide) { | 500 } else if (instruction is !HSubtract && instruction is !HDivide) { |
| 501 return false; | 501 return false; |
| 502 } | 502 } |
| 503 | 503 |
| 504 HBinaryArithmetic binary = instruction; |
| 505 assert(binary.inputs.length == 3); |
| 504 // Is it a builtin operation involving constant numbers? | 506 // Is it a builtin operation involving constant numbers? |
| 505 if (instruction.builtin && instruction.inputs.length == 3) { | 507 if (binary.builtin) { |
| 506 var left = instruction.inputs[1]; | 508 var left = binary.left; |
| 507 var right = instruction.inputs[2]; | 509 var right = binary.right; |
| 508 if (left.isConstantNumber() && isCommutative) { | 510 if (left.isConstantNumber() && isCommutative) { |
| 509 var tmp = right; | 511 var tmp = right; |
| 510 right = left; | 512 right = left; |
| 511 left = tmp; | 513 left = tmp; |
| 512 } else if (!right.isConstantNumber()) { | 514 } else if (!right.isConstantNumber()) { |
| 513 return false; | 515 return false; |
| 514 } | 516 } |
| 515 // Right is constant number. | 517 // Right is constant number. |
| 516 var value = right.constant.value; | 518 HConstant constantRight = right; |
| 519 NumConstant numberConstant = constantRight.constant; |
| 520 num value = numberConstant.value; |
| 517 // Check that left has the same name as the definition and emit | 521 // Check that left has the same name as the definition and emit |
| 518 // the short update definition if it is. | 522 // the short update definition if it is. |
| 519 if (variableNames.getName(left) == name) { | 523 if (variableNames.getName(left) == name) { |
| 520 if (instruction is HAdd && right.constant.value == 1) { | 524 if (binary is HAdd && value == 1) { |
| 521 buffer.add('++'); | 525 buffer.add('++'); |
| 522 declareVariable(name); | 526 declareVariable(name); |
| 523 } else if (instruction is HSubtract && right.constant.value == 1) { | 527 } else if (binary is HSubtract && value == 1) { |
| 524 buffer.add('--'); | 528 buffer.add('--'); |
| 525 declareVariable(name); | 529 declareVariable(name); |
| 526 } else { | 530 } else { |
| 527 var operation = instruction.operation.name; | 531 var operation = binary.operation.name; |
| 528 declareVariable(name); | 532 declareVariable(name); |
| 529 buffer.add(' ${operation}= ${value}'); | 533 buffer.add(' ${operation}= ${value}'); |
| 530 } | 534 } |
| 531 return true; | 535 return true; |
| 532 } | 536 } |
| 533 } | 537 } |
| 534 return false; | 538 return false; |
| 535 } | 539 } |
| 536 | 540 |
| 537 // For simple type checks like i = intTypeCheck(i), we don't have to | 541 // For simple type checks like i = intTypeCheck(i), we don't have to |
| (...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 } | 2478 } |
| 2475 | 2479 |
| 2476 int maxBailoutParameters; | 2480 int maxBailoutParameters; |
| 2477 | 2481 |
| 2478 HBasicBlock beginGraph(HGraph graph) => graph.entry; | 2482 HBasicBlock beginGraph(HGraph graph) => graph.entry; |
| 2479 void endGraph(HGraph graph) {} | 2483 void endGraph(HGraph graph) {} |
| 2480 | 2484 |
| 2481 void bailout(HTypeGuard guard, String reason) { | 2485 void bailout(HTypeGuard guard, String reason) { |
| 2482 if (maxBailoutParameters === null) { | 2486 if (maxBailoutParameters === null) { |
| 2483 maxBailoutParameters = 0; | 2487 maxBailoutParameters = 0; |
| 2484 work.guards.forEach((HTypeGuard guard) { | 2488 work.guards.forEach((HTypeGuard workGuard) { |
| 2485 int inputLength = guard.inputs.length; | 2489 int inputLength = workGuard.inputs.length; |
| 2486 if (inputLength > maxBailoutParameters) { | 2490 if (inputLength > maxBailoutParameters) { |
| 2487 maxBailoutParameters = inputLength; | 2491 maxBailoutParameters = inputLength; |
| 2488 } | 2492 } |
| 2489 }); | 2493 }); |
| 2490 } | 2494 } |
| 2491 HInstruction input = guard.guarded; | 2495 HInstruction input = guard.guarded; |
| 2492 Namer namer = compiler.namer; | 2496 Namer namer = compiler.namer; |
| 2493 Element element = work.element; | 2497 Element element = work.element; |
| 2494 buffer.add('return '); | 2498 buffer.add('return '); |
| 2495 if (element.isInstanceMember()) { | 2499 if (element.isInstanceMember()) { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 startBailoutSwitch(); | 2898 startBailoutSwitch(); |
| 2895 } | 2899 } |
| 2896 } | 2900 } |
| 2897 | 2901 |
| 2898 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2902 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2899 if (labeledBlockInfo.body.start.hasGuards()) { | 2903 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2900 endBailoutSwitch(); | 2904 endBailoutSwitch(); |
| 2901 } | 2905 } |
| 2902 } | 2906 } |
| 2903 } | 2907 } |
| OLD | NEW |