Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10562002: Extend the {+,-,/,*}= support by allowing non-constants on the right side. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Is it a builtin operation involving constant numbers? 504 // Is it a builtin operation involving +, -, /, or *?
505 if (instruction.builtin && instruction.inputs.length == 3) { 505 if (instruction.builtin && instruction.inputs.length == 3) {
506 var left = instruction.inputs[1]; 506 var left = instruction.inputs[1];
507 var right = instruction.inputs[2]; 507 var right = instruction.inputs[2];
508 if (left.isConstantNumber() && isCommutative) { 508 if (isCommutative && variableNames.getName(right) == name) {
509 var tmp = right; 509 var tmp = right;
510 right = left; 510 right = left;
511 left = tmp; 511 left = tmp;
512 } else if (!right.isConstantNumber()) {
513 return false;
514 } 512 }
515 // Right is constant number. 513
516 var value = right.constant.value;
517 // Check that left has the same name as the definition and emit 514 // Check that left has the same name as the definition and emit
518 // the short update definition if it is. 515 // the short update definition if it is.
519 if (variableNames.getName(left) == name) { 516 if (variableNames.getName(left) == name) {
520 if (instruction is HAdd && right.constant.value == 1) { 517 // Check if the right operand is constant one.
518 bool rightIsOne = false;
519 if (right.isConstantNumber()) {
520 HConstant rightConstant = right;
521 rightIsOne = (rightConstant.constant.value == 1);
522 }
523 if (instruction is HAdd && rightIsOne) {
524 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
521 buffer.add('++'); 525 buffer.add('++');
522 declareVariable(name); 526 declareVariable(name);
523 } else if (instruction is HSubtract && right.constant.value == 1) { 527 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
528 } else if (instruction is HSubtract && rightIsOne) {
529 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
524 buffer.add('--'); 530 buffer.add('--');
525 declareVariable(name); 531 declareVariable(name);
532 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
526 } else { 533 } else {
527 var operation = instruction.operation.name; 534 var operation = instruction.operation.name;
535 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
528 declareVariable(name); 536 declareVariable(name);
529 buffer.add(' ${operation}= ${value}'); 537 buffer.add(' ${operation}= ');
538 use(right, JSPrecedence.ASSIGNMENT_PRECEDENCE);
539 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
530 } 540 }
531 return true; 541 return true;
532 } 542 }
533 } 543 }
534 return false; 544 return false;
535 } 545 }
536 546
537 // For simple type checks like i = intTypeCheck(i), we don't have to 547 // For simple type checks like i = intTypeCheck(i), we don't have to
538 // emit an assignment, because the intTypeCheck just returns its 548 // emit an assignment, because the intTypeCheck just returns its
539 // argument. 549 // argument.
(...skipping 2359 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 startBailoutSwitch(); 2909 startBailoutSwitch();
2900 } 2910 }
2901 } 2911 }
2902 2912
2903 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2913 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2904 if (labeledBlockInfo.body.start.hasGuards()) { 2914 if (labeledBlockInfo.body.start.hasGuards()) {
2905 endBailoutSwitch(); 2915 endBailoutSwitch();
2906 } 2916 }
2907 } 2917 }
2908 } 2918 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698