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

Unified Diff: lib/compiler/implementation/ssa/optimize.dart

Issue 10119010: Start propagating non-primitive types in the backend, and fold instructions that know about the typ… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
Index: lib/compiler/implementation/ssa/optimize.dart
===================================================================
--- lib/compiler/implementation/ssa/optimize.dart (revision 6686)
+++ lib/compiler/implementation/ssa/optimize.dart (working copy)
@@ -147,16 +147,67 @@
}
HInstruction visitInvokeInterceptor(HInvokeInterceptor node) {
- if (node.name == const SourceString('length') &&
- node.inputs[1].isConstantString()) {
- HConstant input = node.inputs[1];
- StringConstant constant = input.constant;
- DartString string = constant.value;
- return graph.addConstantInt(string.length);
+ if (node.isLengthGetter()) {
+ HInstruction input = node.inputs[1];
+ if (input.isConstantString()) {
+ StringConstant constant = input.constant;
+ return graph.addConstantInt(constant.length);
+ } else if (input.isConstantList()) {
+ ListConstant constant = input.constant;
+ return graph.addConstantInt(constant.length);
+ } else if (input.isConstantMap()) {
+ MapConstant constant = input.constant;
+ return graph.addConstantInt(constant.length);
+ }
}
return node;
}
+ HInstruction visitInvokeDynamic(HInvokeDynamic node) {
+ HType receiverType = node.receiver.propagatedType;
+ if (receiverType.isNonPrimitive()) {
+ HNonPrimitiveType type = receiverType;
+ Element element = type.lookupMember(node.name);
+ // TODO(ngeoffray): Also fold if it's a getter or variable.
+ if (element != null && element.isFunction()) {
+ FunctionElement method = element;
+ FunctionParameters parameters = method.computeParameters(compiler);
+ if (node.selector.applies(parameters)) {
floitsch 2012/04/18 19:18:48 Even if the function doesn't apply we should set t
ngeoffray 2012/04/19 08:09:33 Why? There is no need to compile the function sinc
+ if (parameters.optionalParameterCount == 0) {
+ node.element = element;
+ }
+ // TODO(ngeoffray): If the method has optional parameters,
+ // we should pass the default values here.
+ }
+ }
+ }
+ return node;
+ }
+
+ HInstruction visitIndex(HIndex node) {
kasperl 2012/04/19 06:46:19 This looks like this could be refactored with a he
ngeoffray 2012/04/19 08:09:33 Done.
+ if (node.receiver.isNonPrimitive()) {
+ return new HInvokeDynamicMethod(
+ node.selector,
+ Elements.constructOperatorName(
+ const SourceString('operator'),
+ const SourceString('[]')),
+ node.inputs.getRange(1, node.inputs.length - 1));
+ }
+ return node;
+ }
+
+ HInstruction visitIndexAssign(HIndexAssign node) {
+ if (node.receiver.isNonPrimitive()) {
+ return new HInvokeDynamicMethod(
+ node.selector,
+ Elements.constructOperatorName(
+ const SourceString('operator'),
+ const SourceString('[]=')),
+ node.inputs.getRange(1, node.inputs.length - 1));
+ }
+ return node;
+ }
+
HInstruction visitInvokeBinary(HInvokeBinary node) {
HInstruction left = node.left;
HInstruction right = node.right;
@@ -167,6 +218,15 @@
Constant folded = operation.fold(op1.constant, op2.constant);
if (folded !== null) return graph.addConstant(folded);
}
+
+ if (left.isNonPrimitive() && node.operation.isUserDefinable()) {
+ return new HInvokeDynamicMethod(
+ node.selector,
+ Elements.constructOperatorName(
+ const SourceString('operator'),
+ node.operation.name),
+ node.inputs.getRange(1, node.inputs.length - 1));
+ }
return node;
}
@@ -180,6 +240,18 @@
node.block.addBefore(node,target);
return new HEquals(target, node.left, node.right);
}
+
+ if (left.isNonPrimitive()) {
kasperl 2012/04/19 06:46:19 Add a comment here that explains what this does. E
+ HNonPrimitiveType type = left.propagatedType;
+ Element element = type.lookupMember(Namer.OPERATOR_EQUALS);
+ if (element === null) {
+ // TODO(floitsch): cache interceptors.
+ HStatic target = new HStatic(
+ compiler.builder.interceptors.getTripleEqualsInterceptor());
+ return new HIdentity(target, left, right);
+ }
+ }
+
// All other cases are dealt with by the [visitInvokeBinary].
return visitInvokeBinary(node);
}

Powered by Google App Engine
This is Rietveld 408576698