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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/codegen.dart
diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart
index ca11aacff27e71d270275793cefd26840ec70e83..779ff35e47f1be5794f37fb16b754a5035c5127c 100644
--- a/lib/compiler/implementation/ssa/codegen.dart
+++ b/lib/compiler/implementation/ssa/codegen.dart
@@ -501,32 +501,42 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
return false;
}
- // Is it a builtin operation involving constant numbers?
+ // Is it a builtin operation involving +, -, /, or *?
if (instruction.builtin && instruction.inputs.length == 3) {
var left = instruction.inputs[1];
var right = instruction.inputs[2];
- if (left.isConstantNumber() && isCommutative) {
+ if (isCommutative && variableNames.getName(right) == name) {
var tmp = right;
right = left;
left = tmp;
- } else if (!right.isConstantNumber()) {
- return false;
}
- // Right is constant number.
- var value = right.constant.value;
+
// Check that left has the same name as the definition and emit
// the short update definition if it is.
if (variableNames.getName(left) == name) {
- if (instruction is HAdd && right.constant.value == 1) {
+ // Check if the right operand is constant one.
+ bool rightIsOne = false;
+ if (right.isConstantNumber()) {
+ HConstant rightConstant = right;
+ rightIsOne = (rightConstant.constant.value == 1);
+ }
+ if (instruction is HAdd && rightIsOne) {
+ beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
buffer.add('++');
declareVariable(name);
- } else if (instruction is HSubtract && right.constant.value == 1) {
+ endExpression(JSPrecedence.PREFIX_PRECEDENCE);
+ } else if (instruction is HSubtract && rightIsOne) {
+ beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
buffer.add('--');
declareVariable(name);
+ endExpression(JSPrecedence.PREFIX_PRECEDENCE);
} else {
var operation = instruction.operation.name;
+ beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
declareVariable(name);
- buffer.add(' ${operation}= ${value}');
+ buffer.add(' ${operation}= ');
+ use(right, JSPrecedence.ASSIGNMENT_PRECEDENCE);
+ endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
}
return true;
}
« 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