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

Side by Side Diff: pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart

Issue 2518553003: Mark some string operations as GVN-able. (Closed)
Patch Set: format Created 3 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
« no previous file with comments | « no previous file | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import '../compiler.dart' show Compiler; 5 import '../compiler.dart' show Compiler;
6 import '../constants/constant_system.dart'; 6 import '../constants/constant_system.dart';
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../js_backend/js_backend.dart'; 9 import '../js_backend/js_backend.dart';
10 import '../types/types.dart'; 10 import '../types/types.dart';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (name == '<=') return const LessEqualSpecializer(); 65 if (name == '<=') return const LessEqualSpecializer();
66 if (name == '>') return const GreaterSpecializer(); 66 if (name == '>') return const GreaterSpecializer();
67 if (name == '>=') return const GreaterEqualSpecializer(); 67 if (name == '>=') return const GreaterEqualSpecializer();
68 return const InvokeDynamicSpecializer(); 68 return const InvokeDynamicSpecializer();
69 } 69 }
70 if (selector.isCall) { 70 if (selector.isCall) {
71 if (selector.namedArguments.length == 0) { 71 if (selector.namedArguments.length == 0) {
72 int argumentCount = selector.argumentCount; 72 int argumentCount = selector.argumentCount;
73 if (argumentCount == 0) { 73 if (argumentCount == 0) {
74 if (name == 'round') return const RoundSpecializer(); 74 if (name == 'round') return const RoundSpecializer();
75 if (name == 'trim') return const TrimSpecializer();
75 } else if (argumentCount == 1) { 76 } else if (argumentCount == 1) {
76 if (name == 'codeUnitAt') return const CodeUnitAtSpecializer(); 77 if (name == 'codeUnitAt') return const CodeUnitAtSpecializer();
77 if (name == 'remainder') return const RemainderSpecializer(); 78 if (name == 'remainder') return const RemainderSpecializer();
79 if (name == 'substring') return const SubstringSpecializer();
80 if (name == 'contains') return const PatternMatchSpecializer();
81 if (name == 'indexOf') return const PatternMatchSpecializer();
82 if (name == 'startsWith') return const PatternMatchSpecializer();
83 if (name == 'endsWith') return const PatternMatchSpecializer();
84 } else if (argumentCount == 2) {
85 if (name == 'substring') return const SubstringSpecializer();
86 if (name == 'contains') return const PatternMatchSpecializer();
87 if (name == 'indexOf') return const PatternMatchSpecializer();
88 if (name == 'startsWith') return const PatternMatchSpecializer();
89 if (name == 'endsWith') return const PatternMatchSpecializer();
78 } 90 }
79 } 91 }
80 } 92 }
81 return const InvokeDynamicSpecializer(); 93 return const InvokeDynamicSpecializer();
82 } 94 }
83 } 95 }
84 96
85 class IndexAssignSpecializer extends InvokeDynamicSpecializer { 97 class IndexAssignSpecializer extends InvokeDynamicSpecializer {
86 const IndexAssignSpecializer(); 98 const IndexAssignSpecializer();
87 99
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 if (receiver.isStringOrNull(closedWorld)) { 852 if (receiver.isStringOrNull(closedWorld)) {
841 // Even if there is no builtin equivalent instruction, we know 853 // Even if there is no builtin equivalent instruction, we know
842 // String.codeUnitAt does not have any side effect (other than throwing), 854 // String.codeUnitAt does not have any side effect (other than throwing),
843 // and that it can be GVN'ed. 855 // and that it can be GVN'ed.
844 clearAllSideEffects(instruction); 856 clearAllSideEffects(instruction);
845 } 857 }
846 return null; 858 return null;
847 } 859 }
848 } 860 }
849 861
862 class IdempotentStringOperationSpecializer extends InvokeDynamicSpecializer {
863 const IdempotentStringOperationSpecializer();
864
865 HInstruction tryConvertToBuiltin(
866 HInvokeDynamic instruction, Compiler compiler, ClosedWorld closedWorld) {
867 HInstruction receiver = instruction.getDartReceiver(closedWorld);
868 if (receiver.isStringOrNull(closedWorld)) {
869 // String.xxx does not have any side effect (other than throwing), and it
870 // can be GVN'ed.
871 clearAllSideEffects(instruction);
872 }
873 return null;
874 }
875 }
876
877 class SubstringSpecializer extends IdempotentStringOperationSpecializer {
878 const SubstringSpecializer();
879 }
880
881 class TrimSpecializer extends IdempotentStringOperationSpecializer {
882 const TrimSpecializer();
883 }
884
885 class PatternMatchSpecializer extends InvokeDynamicSpecializer {
886 const PatternMatchSpecializer();
887
888 HInstruction tryConvertToBuiltin(
889 HInvokeDynamic instruction, Compiler compiler, ClosedWorld closedWorld) {
890 HInstruction receiver = instruction.getDartReceiver(closedWorld);
891 HInstruction pattern = instruction.inputs[2];
892 if (receiver.isStringOrNull(closedWorld) &&
893 pattern.isStringOrNull(closedWorld)) {
894 // String.contains(String s) does not have any side effect (other than
895 // throwing), and it can be GVN'ed.
896 clearAllSideEffects(instruction);
897 }
898 return null;
899 }
900 }
901
850 class RoundSpecializer extends InvokeDynamicSpecializer { 902 class RoundSpecializer extends InvokeDynamicSpecializer {
851 const RoundSpecializer(); 903 const RoundSpecializer();
852 904
853 UnaryOperation operation(ConstantSystem constantSystem) { 905 UnaryOperation operation(ConstantSystem constantSystem) {
854 return constantSystem.round; 906 return constantSystem.round;
855 } 907 }
856 908
857 HInstruction tryConvertToBuiltin( 909 HInstruction tryConvertToBuiltin(
858 HInvokeDynamic instruction, Compiler compiler, ClosedWorld closedWorld) { 910 HInvokeDynamic instruction, Compiler compiler, ClosedWorld closedWorld) {
859 HInstruction receiver = instruction.getDartReceiver(closedWorld); 911 HInstruction receiver = instruction.getDartReceiver(closedWorld);
860 if (receiver.isNumberOrNull(closedWorld)) { 912 if (receiver.isNumberOrNull(closedWorld)) {
861 // Even if there is no builtin equivalent instruction, we know the 913 // Even if there is no builtin equivalent instruction, we know the
862 // instruction does not have any side effect, and that it can be GVN'ed. 914 // instruction does not have any side effect, and that it can be GVN'ed.
863 clearAllSideEffects(instruction); 915 clearAllSideEffects(instruction);
864 } 916 }
865 return null; 917 return null;
866 } 918 }
867 } 919 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698