Simplify SameParameterValueOptimizer. Conceptually SameParameterValueOptimizer could only work on methods that could be statified so we could just wait them until statification completes to do the optimization instead of trying to handle overrides. Change-Id: I73912475706413e74a157ff06608a33b37aa4061
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java index 2434147..02414f2 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
@@ -17,7 +17,6 @@ import com.google.gwt.dev.jjs.ast.Context; import com.google.gwt.dev.jjs.ast.JBinaryOperation; -import com.google.gwt.dev.jjs.ast.JConstructor; import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JMethod; import com.google.gwt.dev.jjs.ast.JMethodCall; @@ -65,15 +64,8 @@ public void endVisit(JMethodCall x, Context ctx) { JMethod method = x.getTarget(); - if (x.canBePolymorphic() || rescuedMethods.contains(method) - /* - * Don't optimize calls visible to JS callers, because you don't know what - * parameter values they'll supply. - */ - || program.isJsTypePrototype(method.getEnclosingType()) - || method.isOrOverridesJsTypeMethod() - || method.isOrOverridesJsFunctionMethod() - || method.isExported()) { + // A quick check to reduce extra work needed otherwise... + if (isNotOptimizable(method)) { return; } @@ -122,30 +114,22 @@ @Override public void endVisit(JsniMethodBody x, Context ctx) { for (JsniMethodRef methodRef : x.getJsniMethodRefs()) { - rescuedMethods.add(methodRef.getTarget()); + nonOptimizableMethods.add(methodRef.getTarget()); } } @Override - public boolean visit(JConstructor x, Context ctx) { - // Cannot be overridden or staticified. - return true; - } - - @Override public boolean visit(JMethod x, Context ctx) { - Set<JMethod> overriddenMethods = x.getOverriddenMethods(); - if (!overriddenMethods.isEmpty() || x.isOrOverridesJsTypeMethod() - || x.isOrOverridesJsFunctionMethod() - || x.isExported()) { - for (JMethod m : overriddenMethods) { - rescuedMethods.add(m); - } - rescuedMethods.add(x); + if (isNotOptimizable(x)) { + nonOptimizableMethods.add(x); } return true; } + private boolean isNotOptimizable(JMethod x) { + return x.needsVtable() || x.isExported(); + } + private boolean equalLiterals(JValueLiteral l1, JValueLiteral l2) { Object v1 = l1.getValueObj(); Object v2 = l2.getValueObj(); @@ -214,12 +198,10 @@ private final JProgram program; /** - * These methods should not be tried to optimized due to their polymorphic - * nature. - * - * TODO: support polymorphic calls properly. + * These methods should not be tried to be optimized, either because they are polymorphic or we + * cannot see all the calls. */ - private final Set<JMethod> rescuedMethods = new HashSet<JMethod>(); + private final Set<JMethod> nonOptimizableMethods = new HashSet<JMethod>(); private SameParameterValueOptimizer(JProgram program) { this.program = program; @@ -231,7 +213,7 @@ analysisVisitor.accept(node); for (JParameter parameter : parameterValues.keySet()) { - if (rescuedMethods.contains(parameter.getEnclosingMethod())) { + if (nonOptimizableMethods.contains(parameter.getEnclosingMethod())) { continue; } JValueLiteral valueLiteral = parameterValues.get(parameter);