| 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Is it a builtin operation involving +, -, /, or *? | 504 // Is it a builtin operation involving +, -, /, or *? |
| 505 if (instruction.builtin && instruction.inputs.length == 3) { | 505 HBinaryArithmetic binaryInstruction = instruction; |
| 506 var left = instruction.inputs[1]; | 506 assert(binaryInstruction.inputs.length == 3); |
| 507 var right = instruction.inputs[2]; | 507 if (binaryInstruction.builtin) { |
| 508 var left = binaryInstruction.left; |
| 509 var right = binaryInstruction.right; |
| 508 if (isCommutative && variableNames.getName(right) == name) { | 510 if (isCommutative && variableNames.getName(right) == name) { |
| 509 var tmp = right; | 511 var tmp = right; |
| 510 right = left; | 512 right = left; |
| 511 left = tmp; | 513 left = tmp; |
| 512 } | 514 } |
| 513 | 515 |
| 514 // Check that left has the same name as the definition and emit | 516 // Check that left has the same name as the definition and emit |
| 515 // the short update definition if it is. | 517 // the short update definition if it is. |
| 516 if (variableNames.getName(left) == name) { | 518 if (variableNames.getName(left) == name) { |
| 517 // Check if the right operand is constant one. | 519 // Check if the right operand is constant one. |
| 518 bool rightIsOne = false; | 520 bool rightIsOne = false; |
| 519 if (right.isConstantNumber()) { | 521 if (right.isConstantNumber()) { |
| 520 HConstant rightConstant = right; | 522 HConstant rightConstant = right; |
| 521 rightIsOne = (rightConstant.constant.value == 1); | 523 NumConstant numConstant = rightConstant.constant; |
| 524 rightIsOne = (numConstant.value == 1); |
| 522 } | 525 } |
| 523 if (instruction is HAdd && rightIsOne) { | 526 if (binaryInstruction is HAdd && rightIsOne) { |
| 524 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); | 527 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 525 buffer.add('++'); | 528 buffer.add('++'); |
| 526 declareVariable(name); | 529 declareVariable(name); |
| 527 endExpression(JSPrecedence.PREFIX_PRECEDENCE); | 530 endExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 528 } else if (instruction is HSubtract && rightIsOne) { | 531 } else if (binaryInstruction is HSubtract && rightIsOne) { |
| 529 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); | 532 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 530 buffer.add('--'); | 533 buffer.add('--'); |
| 531 declareVariable(name); | 534 declareVariable(name); |
| 532 endExpression(JSPrecedence.PREFIX_PRECEDENCE); | 535 endExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 533 } else { | 536 } else { |
| 534 var operation = instruction.operation.name; | 537 var operation = binaryInstruction.operation.name; |
| 535 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); | 538 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); |
| 536 declareVariable(name); | 539 declareVariable(name); |
| 537 buffer.add(' ${operation}= '); | 540 buffer.add(' ${operation}= '); |
| 538 use(right, JSPrecedence.ASSIGNMENT_PRECEDENCE); | 541 use(right, JSPrecedence.ASSIGNMENT_PRECEDENCE); |
| 539 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); | 542 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); |
| 540 } | 543 } |
| 541 return true; | 544 return true; |
| 542 } | 545 } |
| 543 } | 546 } |
| 544 return false; | 547 return false; |
| (...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 } | 2487 } |
| 2485 | 2488 |
| 2486 int maxBailoutParameters; | 2489 int maxBailoutParameters; |
| 2487 | 2490 |
| 2488 HBasicBlock beginGraph(HGraph graph) => graph.entry; | 2491 HBasicBlock beginGraph(HGraph graph) => graph.entry; |
| 2489 void endGraph(HGraph graph) {} | 2492 void endGraph(HGraph graph) {} |
| 2490 | 2493 |
| 2491 void bailout(HTypeGuard guard, String reason) { | 2494 void bailout(HTypeGuard guard, String reason) { |
| 2492 if (maxBailoutParameters === null) { | 2495 if (maxBailoutParameters === null) { |
| 2493 maxBailoutParameters = 0; | 2496 maxBailoutParameters = 0; |
| 2494 work.guards.forEach((HTypeGuard guard) { | 2497 work.guards.forEach((HTypeGuard workGuard) { |
| 2495 int inputLength = guard.inputs.length; | 2498 int inputLength = workGuard.inputs.length; |
| 2496 if (inputLength > maxBailoutParameters) { | 2499 if (inputLength > maxBailoutParameters) { |
| 2497 maxBailoutParameters = inputLength; | 2500 maxBailoutParameters = inputLength; |
| 2498 } | 2501 } |
| 2499 }); | 2502 }); |
| 2500 } | 2503 } |
| 2501 HInstruction input = guard.guarded; | 2504 HInstruction input = guard.guarded; |
| 2502 Namer namer = compiler.namer; | 2505 Namer namer = compiler.namer; |
| 2503 Element element = work.element; | 2506 Element element = work.element; |
| 2504 buffer.add('return '); | 2507 buffer.add('return '); |
| 2505 if (element.isInstanceMember()) { | 2508 if (element.isInstanceMember()) { |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2909 startBailoutSwitch(); | 2912 startBailoutSwitch(); |
| 2910 } | 2913 } |
| 2911 } | 2914 } |
| 2912 | 2915 |
| 2913 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2916 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2914 if (labeledBlockInfo.body.start.hasGuards()) { | 2917 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2915 endBailoutSwitch(); | 2918 endBailoutSwitch(); |
| 2916 } | 2919 } |
| 2917 } | 2920 } |
| 2918 } | 2921 } |
| OLD | NEW |