Index: sdk/lib/_internal/compiler/implementation/ssa/optimize.dart |
=================================================================== |
--- sdk/lib/_internal/compiler/implementation/ssa/optimize.dart (revision 15445) |
+++ sdk/lib/_internal/compiler/implementation/ssa/optimize.dart (working copy) |
@@ -45,6 +45,7 @@ |
new SsaDeadPhiEliminator(), |
new SsaConstantFolder(constantSystem, backend, work, types), |
new SsaTypePropagator(compiler, types), |
+ new SsaReceiverSpecialization(compiler), |
new SsaGlobalValueNumberer(compiler, types), |
new SsaCodeMotion(), |
new SsaValueRangeAnalyzer(constantSystem, types, work), |
@@ -1416,3 +1417,32 @@ |
}); |
} |
} |
+ |
+/** |
+ * This phase specializes dominated uses of a call, where the call |
+ * can give us some type information of what the receiver might be. |
+ * For example, after a call to [:a.foo():], if [:foo:] is only |
+ * in class [:A:], a can be of type [:A:]. |
+ */ |
+class SsaReceiverSpecialization extends HBaseVisitor |
+ implements OptimizationPhase { |
+ final String name = "SsaReceiverSpecialization"; |
+ final Compiler compiler; |
+ |
+ SsaReceiverSpecialization(this.compiler); |
+ |
+ void visitGraph(HGraph graph) { |
+ visitDominatorTree(graph); |
+ } |
+ |
+ void visitInterceptor(HInterceptor interceptor) { |
+ HInstruction receiver = interceptor.receiver; |
+ for (var user in receiver.usedBy) { |
+ if (user is HInterceptor && interceptor.dominates(user)) { |
kasperl
2012/11/29 08:22:27
This is probably fine, but an alternative implemen
ngeoffray
2012/11/29 08:31:56
Good point. Filed http://code.google.com/p/dart/is
|
+ user.interceptedClasses = interceptor.interceptedClasses; |
+ } |
+ } |
+ } |
+ |
+ // TODO(ngeoffray): Also implement it for non-intercepted calls. |
+} |