changeset 19536:2c3ea61e8b65

Small clean up for graph building.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 22 Feb 2015 15:37:46 +0100
parents 97b35083d49d
children 9d5003af91f5
files graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java
diffstat 2 files changed, 62 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Sun Feb 22 15:19:54 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Sun Feb 22 15:37:46 2015 +0100
@@ -1501,45 +1501,27 @@
 
             protected void processBlock(BytecodeParser parser, BciBlock block) {
                 // Ignore blocks that have no predecessors by the time their bytecodes are parsed
-                if (block == null || getFirstInstruction(block, this.getCurrentDimension()) == null) {
+                int currentDimension = this.getCurrentDimension();
+                FixedWithNextNode firstInstruction = getFirstInstruction(block, currentDimension);
+                if (firstInstruction == null) {
                     Debug.log("Ignoring block %s", block);
                     return;
                 }
-                try (Indent indent = Debug.logAndIndent("Parsing block %s  firstInstruction: %s  loopHeader: %b", block, getFirstInstruction(block, this.getCurrentDimension()), block.isLoopHeader)) {
+                try (Indent indent = Debug.logAndIndent("Parsing block %s  firstInstruction: %s  loopHeader: %b", block, firstInstruction, block.isLoopHeader)) {
 
-                    lastInstr = getFirstInstruction(block, this.getCurrentDimension());
-                    frameState = getEntryState(block, this.getCurrentDimension());
+                    lastInstr = firstInstruction;
+                    frameState = getEntryState(block, currentDimension);
                     parser.setCurrentFrameState(frameState);
                     currentBlock = block;
 
-                    if (lastInstr instanceof AbstractMergeNode) {
-
-                        AbstractMergeNode abstractMergeNode = (AbstractMergeNode) lastInstr;
-                        if (abstractMergeNode.stateAfter() == null) {
-                            int bci = block.startBci;
-                            if (block instanceof ExceptionDispatchBlock) {
-                                bci = ((ExceptionDispatchBlock) block).deoptBci;
-                            }
-                            abstractMergeNode.setStateAfter(frameState.create(bci));
-                        }
+                    if (firstInstruction instanceof AbstractMergeNode) {
+                        setMergeStateAfter(block, firstInstruction);
                     }
 
                     if (block == blockMap.getReturnBlock()) {
-                        Kind returnKind = method.getSignature().getReturnKind().getStackKind();
-                        ValueNode x = returnKind == Kind.Void ? null : frameState.pop(returnKind);
-                        assert frameState.stackSize() == 0;
-                        beforeReturn(x);
-                        this.returnValue = x;
-                        this.beforeReturnNode = this.lastInstr;
+                        handleReturnBlock();
                     } else if (block == blockMap.getUnwindBlock()) {
-                        if (currentDepth == 0) {
-                            frameState.setRethrowException(false);
-                            createUnwind();
-                        } else {
-                            ValueNode exception = frameState.apop();
-                            this.unwindValue = exception;
-                            this.beforeUnwindNode = this.lastInstr;
-                        }
+                        handleUnwindBlock();
                     } else if (block instanceof ExceptionDispatchBlock) {
                         createExceptionDispatch((ExceptionDispatchBlock) block);
                     } else {
@@ -1549,6 +1531,37 @@
                 }
             }
 
+            private void handleUnwindBlock() {
+                if (currentDepth == 0) {
+                    frameState.setRethrowException(false);
+                    createUnwind();
+                } else {
+                    ValueNode exception = frameState.apop();
+                    this.unwindValue = exception;
+                    this.beforeUnwindNode = this.lastInstr;
+                }
+            }
+
+            private void handleReturnBlock() {
+                Kind returnKind = method.getSignature().getReturnKind().getStackKind();
+                ValueNode x = returnKind == Kind.Void ? null : frameState.pop(returnKind);
+                assert frameState.stackSize() == 0;
+                beforeReturn(x);
+                this.returnValue = x;
+                this.beforeReturnNode = this.lastInstr;
+            }
+
+            private void setMergeStateAfter(BciBlock block, FixedWithNextNode firstInstruction) {
+                AbstractMergeNode abstractMergeNode = (AbstractMergeNode) firstInstruction;
+                if (abstractMergeNode.stateAfter() == null) {
+                    int bci = block.startBci;
+                    if (block instanceof ExceptionDispatchBlock) {
+                        bci = ((ExceptionDispatchBlock) block).deoptBci;
+                    }
+                    abstractMergeNode.setStateAfter(frameState.create(bci));
+                }
+            }
+
             /**
              * Remove loop header without loop ends. This can happen with degenerated loops like
              * this one:
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Sun Feb 22 15:19:54 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Sun Feb 22 15:37:46 2015 +0100
@@ -238,10 +238,18 @@
         assert isCompatibleWith(other);
 
         for (int i = 0; i < localsSize(); i++) {
-            storeLocal(i, merge(localAt(i), other.localAt(i), block));
+            ValueNode curLocal = localAt(i);
+            ValueNode mergedLocal = merge(curLocal, other.localAt(i), block);
+            if (curLocal != mergedLocal) {
+                storeLocal(i, mergedLocal);
+            }
         }
         for (int i = 0; i < stackSize(); i++) {
-            storeStack(i, merge(stackAt(i), other.stackAt(i), block));
+            ValueNode curStack = stackAt(i);
+            ValueNode mergedStack = merge(curStack, other.stackAt(i), block);
+            if (curStack != mergedStack) {
+                storeStack(i, mergedStack);
+            }
         }
         for (int i = 0; i < lockedObjects.length; i++) {
             lockedObjects[i] = merge(lockedObjects[i], other.lockedObjects[i], block);
@@ -252,7 +260,6 @@
     private ValueNode merge(ValueNode currentValue, ValueNode otherValue, AbstractMergeNode block) {
         if (currentValue == null || currentValue.isDeleted()) {
             return null;
-
         } else if (block.isPhiAtMerge(currentValue)) {
             if (otherValue == null || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) {
                 propagateDelete((ValuePhiNode) currentValue);
@@ -260,26 +267,27 @@
             }
             ((PhiNode) currentValue).addInput(otherValue);
             return currentValue;
-
         } else if (currentValue != otherValue) {
             assert !(block instanceof LoopBeginNode) : "Phi functions for loop headers are create eagerly for changed locals and all stack slots";
             if (otherValue == null || otherValue.isDeleted() || currentValue.getKind() != otherValue.getKind()) {
                 return null;
             }
-
-            ValuePhiNode phi = graph.addWithoutUnique(new ValuePhiNode(currentValue.stamp().unrestricted(), block));
-            for (int i = 0; i < block.phiPredecessorCount(); i++) {
-                phi.addInput(currentValue);
-            }
-            phi.addInput(otherValue);
-            assert phi.valueCount() == block.phiPredecessorCount() + 1 : "valueCount=" + phi.valueCount() + " predSize= " + block.phiPredecessorCount();
-            return phi;
-
+            return createValuePhi(currentValue, otherValue, block);
         } else {
             return currentValue;
         }
     }
 
+    private ValuePhiNode createValuePhi(ValueNode currentValue, ValueNode otherValue, AbstractMergeNode block) {
+        ValuePhiNode phi = graph.addWithoutUnique(new ValuePhiNode(currentValue.stamp().unrestricted(), block));
+        for (int i = 0; i < block.phiPredecessorCount(); i++) {
+            phi.addInput(currentValue);
+        }
+        phi.addInput(otherValue);
+        assert phi.valueCount() == block.phiPredecessorCount() + 1;
+        return phi;
+    }
+
     private void propagateDelete(FloatingNode node) {
         assert node instanceof ValuePhiNode || node instanceof ProxyNode;
         if (node.isDeleted()) {