changeset 15988:5aaef6a8985d

[inliner] lazy allocation of param-usages container; documentation
author Miguel Garcia <miguel.m.garcia@oracle.com>
date Sun, 01 Jun 2014 16:06:07 +0200
parents 03b1d8f6b4ef
children f62cc9f09c7b df679a9e6de0 31db7b7374f0
files graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java
diffstat 1 files changed, 28 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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<Node> parameterUsages = replaceParamsWithMoreInformativeArguments(invoke, newGraph, context);
+            ArrayList<Node> 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<ValueNode> 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:
+     * <ul>
+     * <li>
+     * constants among the arguments to the <code>invoke</code></li>
+     * <li>
+     * arguments with more precise type than that declared by the corresponding parameter</li>
+     * </ul>
+     *
+     * <p>
+     * The corresponding parameters are updated to reflect the above information. Before doing so,
+     * their usages are added to <code>parameterUsages</code> for later incremental
+     * canonicalization.
+     * </p>
+     *
+     * @return null if no incremental canonicalization is need, a list of nodes for such
+     *         canonicalization otherwise.
      */
     private static ArrayList<Node> replaceParamsWithMoreInformativeArguments(final Invoke invoke, final StructuredGraph newGraph, final HighTierContext context) {
         NodeInputList<ValueNode> args = invoke.callTarget().arguments();
-        ArrayList<Node> parameterUsages = new ArrayList<>();
+        ArrayList<Node> 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<Node> trackParameterUsages(ParameterNode param, ArrayList<Node> parameterUsages) {
+        ArrayList<Node> 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);