# HG changeset patch # User Miguel Garcia # Date 1401631567 -7200 # Node ID 5aaef6a8985d275539e1ba39357bccf508e63ba1 # Parent 03b1d8f6b4ef7053310808236e865bc7c6342cb2 [inliner] lazy allocation of param-usages container; documentation diff -r 03b1d8f6b4ef -r 5aaef6a8985d 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:41:36 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Sun Jun 01 16:06:07 2014 +0200 @@ -73,12 +73,10 @@ try (Debug.Scope s = Debug.scope("InlineGraph", newGraph)) { - if (existProfitableParamArgReplacements(invoke, newGraph)) { - ArrayList parameterUsages = replaceParamsWithMoreInformativeArguments(invoke, newGraph, context); + ArrayList parameterUsages = replaceParamsWithMoreInformativeArguments(invoke, newGraph, context); + if (parameterUsages != null && OptCanonicalizer.getValue()) { assert !parameterUsages.isEmpty() : "The caller didn't have more information about arguments after all"; - if (OptCanonicalizer.getValue()) { - canonicalizer.applyIncremental(newGraph, context, parameterUsages); - } + canonicalizer.applyIncremental(newGraph, context, parameterUsages); } else { // TODO (chaeubl): if args are not more concrete, inlining should be avoided // in most cases or we could at least use the previous graph size + invoke @@ -91,19 +89,6 @@ } } - 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; @@ -117,25 +102,39 @@ } /** - * This method must adopt the same definition of "more informative argument" as used in - * {@link #existProfitableParamArgReplacements(Invoke, StructuredGraph)} + * This method detects: + *
    + *
  • + * constants among the arguments to the invoke
  • + *
  • + * arguments with more precise type than that declared by the corresponding parameter
  • + *
+ * + *

+ * The corresponding parameters are updated to reflect the above information. Before doing so, + * their usages are added to parameterUsages for later incremental + * canonicalization. + *

+ * + * @return null if no incremental canonicalization is need, a list of nodes for such + * canonicalization otherwise. */ private static ArrayList replaceParamsWithMoreInformativeArguments(final Invoke invoke, final StructuredGraph newGraph, final HighTierContext context) { NodeInputList args = invoke.callTarget().arguments(); - ArrayList parameterUsages = new ArrayList<>(); + ArrayList parameterUsages = null; 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); + parameterUsages = trackParameterUsages(param, 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); + parameterUsages = trackParameterUsages(param, parameterUsages); } else { assert !isArgMoreInformativeThanParam(arg, param); } @@ -145,6 +144,12 @@ return parameterUsages; } + private static ArrayList trackParameterUsages(ParameterNode param, ArrayList parameterUsages) { + ArrayList result = (parameterUsages == null) ? new ArrayList<>() : parameterUsages; + param.usages().snapshotTo(result); + return result; + } + private static StructuredGraph getCachedGraph(ResolvedJavaMethod method, HighTierContext context) { if (context.getGraphCache() != null) { StructuredGraph cachedGraph = context.getGraphCache().get(method);