# HG changeset patch # User Miguel Garcia # Date 1401471696 -7200 # Node ID 03b1d8f6b4ef7053310808236e865bc7c6342cb2 # Parent 23e6edbe4c763bd16ff80510fb2268476e0add29 [inlining] preparations to avoid cloning whenever possible diff -r 23e6edbe4c76 -r 03b1d8f6b4ef graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Fri May 30 19:00:27 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Fri May 30 19:41:36 2014 +0200 @@ -73,27 +73,9 @@ try (Debug.Scope s = Debug.scope("InlineGraph", newGraph)) { - boolean callerHasMoreInformationAboutArguments = false; - NodeInputList args = invoke.callTarget().arguments(); - ArrayList parameterUsages = new ArrayList<>(); - for (ParameterNode param : newGraph.getNodes(ParameterNode.class).snapshot()) { - ValueNode arg = args.get(param.index()); - if (arg.isConstant()) { - Constant constant = arg.asConstant(); - newGraph.replaceFloating(param, ConstantNode.forConstant(constant, context.getMetaAccess(), newGraph)); - callerHasMoreInformationAboutArguments = true; - param.usages().snapshotTo(parameterUsages); - } else { - Stamp joinedStamp = param.stamp().join(arg.stamp()); - if (joinedStamp != null && !joinedStamp.equals(param.stamp())) { - param.setStamp(joinedStamp); - callerHasMoreInformationAboutArguments = true; - param.usages().snapshotTo(parameterUsages); - } - } - } - - if (callerHasMoreInformationAboutArguments) { + if (existProfitableParamArgReplacements(invoke, newGraph)) { + ArrayList parameterUsages = replaceParamsWithMoreInformativeArguments(invoke, newGraph, context); + assert !parameterUsages.isEmpty() : "The caller didn't have more information about arguments after all"; if (OptCanonicalizer.getValue()) { canonicalizer.applyIncremental(newGraph, context, parameterUsages); } @@ -109,6 +91,60 @@ } } + private static boolean existProfitableParamArgReplacements(final Invoke invoke, final StructuredGraph newGraph) { + NodeInputList args = invoke.callTarget().arguments(); + for (ParameterNode param : newGraph.getNodes(ParameterNode.class)) { + if (param.usages().isNotEmpty()) { + ValueNode arg = args.get(param.index()); + if (isArgMoreInformativeThanParam(arg, param)) { + return true; + } + } + } + return false; + } + + private static boolean isArgMoreInformativeThanParam(ValueNode arg, ParameterNode param) { + if (arg.isConstant()) { + return true; + } else { + Stamp joinedStamp = param.stamp().join(arg.stamp()); + if (joinedStamp != null && !joinedStamp.equals(param.stamp())) { + return true; + } + } + return false; + } + + /** + * This method must adopt the same definition of "more informative argument" as used in + * {@link #existProfitableParamArgReplacements(Invoke, StructuredGraph)} + */ + private static ArrayList replaceParamsWithMoreInformativeArguments(final Invoke invoke, final StructuredGraph newGraph, final HighTierContext context) { + NodeInputList args = invoke.callTarget().arguments(); + ArrayList parameterUsages = new ArrayList<>(); + for (ParameterNode param : newGraph.getNodes(ParameterNode.class).snapshot()) { + if (param.usages().isNotEmpty()) { + ValueNode arg = args.get(param.index()); + if (arg.isConstant()) { + Constant constant = arg.asConstant(); + param.usages().snapshotTo(parameterUsages); + // collect param usages before replacing the param + newGraph.replaceFloating(param, ConstantNode.forConstant(constant, context.getMetaAccess(), newGraph)); + } else { + Stamp joinedStamp = param.stamp().join(arg.stamp()); + if (joinedStamp != null && !joinedStamp.equals(param.stamp())) { + param.setStamp(joinedStamp); + param.usages().snapshotTo(parameterUsages); + } else { + assert !isArgMoreInformativeThanParam(arg, param); + } + } + } + } + return parameterUsages; + } + private static StructuredGraph getCachedGraph(ResolvedJavaMethod method, HighTierContext context) { if (context.getGraphCache() != null) { StructuredGraph cachedGraph = context.getGraphCache().get(method);