changeset 10706:8d961f93725c

Use GuardedValueNode in the inlining
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 09 Jul 2013 18:17:55 +0200
parents fd53f9f7007b
children a643c88d164f
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java
diffstat 3 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java	Thu Jul 11 13:09:28 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java	Tue Jul 09 18:17:55 2013 +0200
@@ -26,6 +26,7 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
 
 /**
  * A node that changes the type of its input, usually narrowing it. For example, a GuardedValueNode
@@ -37,13 +38,17 @@
 
     @Input private ValueNode object;
 
-    public ValueNode object() {
-        return object;
+    public GuardedValueNode(ValueNode object, GuardingNode guard, Stamp stamp) {
+        super(stamp, guard);
+        this.object = object;
     }
 
     public GuardedValueNode(ValueNode object, GuardingNode guard) {
-        super(object.stamp(), guard);
-        this.object = object;
+        this(object, guard, object.stamp());
+    }
+
+    public ValueNode object() {
+        return object;
     }
 
     @Override
@@ -68,7 +73,11 @@
 
     public ValueNode canonical(CanonicalizerTool tool) {
         if (getGuard() == graph().start()) {
-            return object();
+            if (stamp().equals(object().stamp())) {
+                return object();
+            } else {
+                return graph().unique(new PiNode(object(), stamp()));
+            }
         }
         return this;
     }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java	Thu Jul 11 13:09:28 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java	Tue Jul 09 18:17:55 2013 +0200
@@ -661,7 +661,7 @@
             invoke.asNode().replaceAtUsages(returnValuePhi);
             invoke.asNode().replaceAndDelete(null);
 
-            ArrayList<PiNode> replacementNodes = new ArrayList<>();
+            ArrayList<GuardedValueNode> replacementNodes = new ArrayList<>();
 
             // do the actual inlining for every invoke
             for (int i = 0; i < numberOfMethods; i++) {
@@ -677,7 +677,7 @@
 
                 ValueNode receiver = ((MethodCallTargetNode) invokeForInlining.callTarget()).receiver();
                 boolean exact = (getTypeCount(i) == 1 && !methodDispatch);
-                PiNode anchoredReceiver = createAnchoredReceiver(graph, node, commonType, receiver, exact);
+                GuardedValueNode anchoredReceiver = createAnchoredReceiver(graph, node, commonType, receiver, exact);
                 invokeForInlining.callTarget().replaceFirstInput(receiver, anchoredReceiver);
 
                 inline(invokeForInlining, methodAt(i), inlineableElementAt(i), assumptions, false);
@@ -956,7 +956,7 @@
 
             invocationEntry.setNext(invoke.asNode());
             ValueNode receiver = ((MethodCallTargetNode) invoke.callTarget()).receiver();
-            PiNode anchoredReceiver = createAnchoredReceiver(graph, invocationEntry, target.getDeclaringClass(), receiver, false);
+            GuardedValueNode anchoredReceiver = createAnchoredReceiver(graph, invocationEntry, target.getDeclaringClass(), receiver, false);
             invoke.callTarget().replaceFirstInput(receiver, anchoredReceiver);
             replaceInvokeCallTarget(invoke, graph, kind, target);
         }
@@ -1216,13 +1216,13 @@
         }
     }
 
-    private static PiNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ResolvedJavaType commonType, ValueNode receiver, boolean exact) {
+    private static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ResolvedJavaType commonType, ValueNode receiver, boolean exact) {
         return createAnchoredReceiver(graph, anchor, receiver, exact ? StampFactory.exactNonNull(commonType) : StampFactory.declaredNonNull(commonType));
     }
 
-    private static PiNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ValueNode receiver, Stamp stamp) {
+    private static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ValueNode receiver, Stamp stamp) {
         // to avoid that floating reads on receiver fields float above the type check
-        return graph.unique(new PiNode(receiver, stamp, anchor));
+        return graph.unique(new GuardedValueNode(receiver, anchor, stamp));
     }
 
     // TODO (chaeubl): cleanup this method
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java	Thu Jul 11 13:09:28 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java	Tue Jul 09 18:17:55 2013 +0200
@@ -159,7 +159,7 @@
      *            {@link PiNode} in the duplicated branch that corresponds to the entry.
      * @param phaseContext
      */
-    public static boolean tailDuplicate(MergeNode merge, TailDuplicationDecision decision, List<PiNode> replacements, PhaseContext phaseContext) {
+    public static boolean tailDuplicate(MergeNode merge, TailDuplicationDecision decision, List<GuardedValueNode> replacements, PhaseContext phaseContext) {
         assert !(merge instanceof LoopBeginNode);
         assert replacements == null || replacements.size() == merge.forwardEndCount();
         FixedNode fixed = merge;
@@ -188,7 +188,7 @@
         private final StructuredGraph graph;
 
         private final HashMap<ValueNode, PhiNode> bottomPhis = new HashMap<>();
-        private final List<PiNode> replacements;
+        private final List<GuardedValueNode> replacements;
 
         /**
          * Initializes the tail duplication operation without actually performing any work.
@@ -197,7 +197,7 @@
          * @param replacements A list of replacement {@link PiNode}s, or null. If this is non-null,
          *            then the size of the list needs to match the number of end nodes at the merge.
          */
-        public DuplicationOperation(MergeNode merge, List<PiNode> replacements) {
+        public DuplicationOperation(MergeNode merge, List<GuardedValueNode> replacements) {
             this.merge = merge;
             this.replacements = replacements;
             this.graph = merge.graph();