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

Side by Side Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 1562893002: dart2js cps: Generate increment and compound operators. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Also compound string concatenation Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library tree_ir.optimization.statement_rewriter; 5 library tree_ir.optimization.statement_rewriter;
6 6
7 import 'optimization.dart' show Pass; 7 import 'optimization.dart' show Pass;
8 import '../tree_ir_nodes.dart'; 8 import '../tree_ir_nodes.dart';
9 import '../../io/source_information.dart'; 9 import '../../io/source_information.dart';
10 import '../../elements/elements.dart'; 10 import '../../elements/elements.dart';
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 } 751 }
752 return node; 752 return node;
753 } 753 }
754 754
755 Expression visitTypeOperator(TypeOperator node) { 755 Expression visitTypeOperator(TypeOperator node) {
756 _rewriteList(node.typeArguments); 756 _rewriteList(node.typeArguments);
757 node.value = visitExpression(node.value); 757 node.value = visitExpression(node.value);
758 return node; 758 return node;
759 } 759 }
760 760
761 bool sameVariable(Expression e1, Expression e2) {
762 return e1 is VariableUse && e2 is VariableUse && e1.variable == e2.variable;
763 }
764
765 bool isCompoundableBuiltin(Expression e) {
766 return e is ApplyBuiltinOperator &&
767 e.arguments.length == 2 &&
768 isCompoundableOperator(e.operator);
769 }
770
771 void destroyVariableUse(VariableUse node) {
772 --node.variable.readCount;
773 }
774
761 Expression visitSetField(SetField node) { 775 Expression visitSetField(SetField node) {
762 allowRhsPropagation.add(true); 776 allowRhsPropagation.add(true);
763 node.value = visitExpression(node.value); 777 node.value = visitExpression(node.value);
778 if (isCompoundableBuiltin(node.value)) {
779 ApplyBuiltinOperator rhs = node.value;
780 Expression left = rhs.arguments[0];
781 Expression right = rhs.arguments[1];
782 if (left is GetField &&
783 left.field == node.field &&
784 sameVariable(left.object, node.object)) {
785 destroyVariableUse(left.object);
786 node.compound = rhs.operator;
787 node.value = right;
788 }
789 }
764 node.object = visitExpression(node.object); 790 node.object = visitExpression(node.object);
765 allowRhsPropagation.removeLast(); 791 allowRhsPropagation.removeLast();
766 return node; 792 return node;
767 } 793 }
768 794
769 Expression visitGetField(GetField node) { 795 Expression visitGetField(GetField node) {
770 node.object = visitExpression(node.object); 796 node.object = visitExpression(node.object);
771 return node; 797 return node;
772 } 798 }
773 799
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 } 853 }
828 854
829 Expression visitGetIndex(GetIndex node) { 855 Expression visitGetIndex(GetIndex node) {
830 node.index = visitExpression(node.index); 856 node.index = visitExpression(node.index);
831 node.object = visitExpression(node.object); 857 node.object = visitExpression(node.object);
832 return node; 858 return node;
833 } 859 }
834 860
835 Expression visitSetIndex(SetIndex node) { 861 Expression visitSetIndex(SetIndex node) {
836 node.value = visitExpression(node.value); 862 node.value = visitExpression(node.value);
863 if (isCompoundableBuiltin(node.value)) {
864 ApplyBuiltinOperator rhs = node.value;
865 Expression left = rhs.arguments[0];
866 Expression right = rhs.arguments[1];
867 if (left is GetIndex &&
868 sameVariable(left.object, node.object) &&
869 sameVariable(left.index, node.index)) {
870 destroyVariableUse(left.object);
871 destroyVariableUse(left.index);
872 node.compound = rhs.operator;
873 node.value = right;
874 }
875 }
837 node.index = visitExpression(node.index); 876 node.index = visitExpression(node.index);
838 node.object = visitExpression(node.object); 877 node.object = visitExpression(node.object);
839 return node; 878 return node;
840 } 879 }
841 880
842 /// True if [operator] is a binary operator that always has the same value 881 /// True if [operator] is a binary operator that always has the same value
843 /// if its arguments are swapped. 882 /// if its arguments are swapped.
844 bool isSymmetricOperator(BuiltinOperator operator) { 883 bool isSymmetricOperator(BuiltinOperator operator) {
845 switch (operator) { 884 switch (operator) {
846 case BuiltinOperator.StrictEq: 885 case BuiltinOperator.StrictEq:
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 VariableUseCallback callback; 1355 VariableUseCallback callback;
1317 1356
1318 VariableUseVisitor(this.callback); 1357 VariableUseVisitor(this.callback);
1319 1358
1320 visitVariableUse(VariableUse use) => callback(use); 1359 visitVariableUse(VariableUse use) => callback(use);
1321 1360
1322 static void visit(Expression node, VariableUseCallback callback) { 1361 static void visit(Expression node, VariableUseCallback callback) {
1323 new VariableUseVisitor(callback).visitExpression(node); 1362 new VariableUseVisitor(callback).visitExpression(node);
1324 } 1363 }
1325 } 1364 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/codegen.dart ('k') | pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698