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

Unified Diff: pkg/compiler/lib/src/cps_ir/type_propagation.dart

Issue 1437373002: dart2js cps: Add CharCodeAt builtin. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
Index: pkg/compiler/lib/src/cps_ir/type_propagation.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
index 61c92001b092648d45cca2ac759f1679e633227b..aa8c972bdda6e298e288589a8a6a6b6ca5837dd4 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -452,6 +452,10 @@ class ConstantPropagationLattice {
return folded ?? closedOnUint(left, right) ?? closedOnInt(left, right);
}
+ AbstractValue codeUnitAtSpecial(AbstractValue left, AbstractValue right) {
+ return foldBinary(constantSystem.codeUnitAt, left, right);
+ }
+
AbstractValue equalSpecial(AbstractValue left, AbstractValue right) {
AbstractValue folded = foldBinary(constantSystem.equal, left, right);
if (folded != null) return folded;
@@ -1141,6 +1145,21 @@ class TransformingVisitor extends DeepRecursiveVisitor {
replaceWithBinary(BuiltinOperator.NumRemainder, receiver, arg);
}
}
+ } else if (name == 'codeUnitAt') {
+ if (node.arguments.length == 2) {
+ Primitive index = node.dartArgument(0);
+ if (lattice.isDefinitelyString(receiverValue) &&
+ lattice.isDefinitelyInt(getValue(index))) {
+ SourceInformation sourceInfo = node.sourceInformation;
+ CpsFragment cps = makeBoundsCheck(receiver, index, sourceInfo);
+ ApplyBuiltinOperator get =
+ cps.applyBuiltin(BuiltinOperator.CharCodeAt,
+ <Primitive>[receiver, index]);
+ node.replaceUsesWith(get);
+ get.hint = node.hint;
+ return cps;
+ }
+ }
}
}
return null;
@@ -2518,15 +2537,34 @@ class TypePropagationVisitor implements Visitor {
return; // And come back later.
}
- // Constant fold known length of containers.
- if (node.selector == Selectors.length) {
- AbstractValue object = getValue(node.dartReceiver);
- if (typeSystem.isDefinitelyIndexable(object.type, allowNull: true)) {
- AbstractValue length = lattice.lengthSpecial(object);
- if (length != null) {
- setResult(node, length, canReplace: !object.isNullable);
+ if (node.selector.isGetter) {
+ // Constant fold known length of containers.
+ if (node.selector == Selectors.length) {
+ AbstractValue object = getValue(node.dartReceiver);
+ if (typeSystem.isDefinitelyIndexable(object.type, allowNull: true)) {
+ AbstractValue length = lattice.lengthSpecial(object);
+ if (length != null) {
+ setResult(node, length, canReplace: !object.isNullable);
+ }
}
}
+ setResult(node, lattice.getInvokeReturnType(node.selector, node.mask));
+ return;
+ }
+
+ if (node.selector.isCall) {
+ AbstractValue result;
+ if (node.selector == Selectors.codeUnitAt) {
+ AbstractValue object = getValue(node.dartReceiver);
+ AbstractValue right = getValue(node.dartArgument(0));
+ result = lattice.codeUnitAtSpecial(object, right);
+ }
+ if (result == null) {
+ setResult(node, lattice.getInvokeReturnType(node.selector, node.mask));
+ } else {
+ setResult(node, result, canReplace: true);
+ }
+ return;
}
if (!node.selector.isOperator) {
@@ -2619,6 +2657,10 @@ class TypePropagationVisitor implements Visitor {
}
break;
+ case BuiltinOperator.CharCodeAt:
+ binaryOp(lattice.codeUnitAtSpecial, typeSystem.uint31Type);
+ break;
+
case BuiltinOperator.Identical:
case BuiltinOperator.StrictEq:
case BuiltinOperator.LooseEq:
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/builtin_operator.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698