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

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

Issue 1477683003: cps_ir: Constant fold lengths of constants (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 68315eb518e9fdb2187afc1b9a0de2cac3d1822e..61c92001b092648d45cca2ac759f1679e633227b 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -522,6 +522,26 @@ class ConstantPropagationLattice {
return foldBinary(constantSystem.greaterEqual, left, right);
}
+ AbstractValue intConstant(int value) {
+ return constant(new IntConstantValue(value));
+ }
+
+ AbstractValue lengthSpecial(AbstractValue input) {
+ if (input.isConstant) {
+ ConstantValue constant = input.constant;
+ if (constant is StringConstantValue) {
+ return intConstant(constant.length);
+ } else if (constant is ListConstantValue) {
+ return intConstant(constant.length);
+ }
+ }
+ int length = typeSystem.getContainerLength(input.type);
+ if (length != null) {
+ return intConstant(length);
+ }
+ return null; // The caller will use return type from type inference.
+ }
+
AbstractValue stringConstant(String value) {
return constant(new StringConstantValue(new ast.DartString.literal(value)));
}
@@ -2502,16 +2522,14 @@ class TypePropagationVisitor implements Visitor {
if (node.selector == Selectors.length) {
AbstractValue object = getValue(node.dartReceiver);
if (typeSystem.isDefinitelyIndexable(object.type, allowNull: true)) {
- int length = typeSystem.getContainerLength(object.type.nonNullable());
+ AbstractValue length = lattice.lengthSpecial(object);
if (length != null) {
- setResult(node, constantValue(new IntConstantValue(length)),
- canReplace: !object.isNullable);
+ setResult(node, length, canReplace: !object.isNullable);
}
}
}
if (!node.selector.isOperator) {
- // TODO(jgruber): Handle known methods on constants such as String.length.
setResult(node, lattice.getInvokeReturnType(node.selector, node.mask));
return;
}
@@ -2959,11 +2977,11 @@ class TypePropagationVisitor implements Visitor {
void visitGetLength(GetLength node) {
AbstractValue input = getValue(node.object.definition);
node.objectIsNotNull = input.isDefinitelyNotNull;
- int length = typeSystem.getContainerLength(input.type);
+ AbstractValue length = lattice.lengthSpecial(input);
if (length != null) {
// TODO(asgerf): Constant-folding the length might degrade the VM's
// own bounds-check elimination?
- setValue(node, constantValue(new IntConstantValue(length)));
+ setValue(node, length);
} else {
setValue(node, nonConstant(typeSystem.uint32Type));
}
« 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