changeset 19532:a9aa368f9068

Improve IfNode construction in the graph builder. Start reusing previous frame states in createTarget.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 22 Feb 2015 14:27:36 +0100
parents 8fc336a04d77
children e5465c0c5828
files graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Fri Feb 20 22:22:55 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Sun Feb 22 14:27:36 2015 +0100
@@ -642,8 +642,8 @@
                 return (ValueNode) currentGraph.unique((Node & ValueNumberable) x);
             }
 
-            protected ValueNode genIfNode(ValueNode condition, ValueNode falseSuccessor, ValueNode trueSuccessor, double d) {
-                return new IfNode((LogicNode) condition, (FixedNode) falseSuccessor, (FixedNode) trueSuccessor, d);
+            protected ValueNode genIfNode(LogicNode condition, FixedNode falseSuccessor, FixedNode trueSuccessor, double d) {
+                return new IfNode(condition, falseSuccessor, trueSuccessor, d);
             }
 
             @Override
@@ -1367,7 +1367,7 @@
                     targetNode = getFirstInstruction(block, operatingDimension);
                     Target target = checkLoopExit(targetNode, block, state);
                     FixedNode result = target.fixed;
-                    HIRFrameStateBuilder currentEntryState = target.state == state ? state.copy() : target.state;
+                    HIRFrameStateBuilder currentEntryState = target.state == state ? (isGoto ? state : state.copy()) : target.state;
                     setEntryState(block, operatingDimension, currentEntryState);
                     currentEntryState.clearNonLiveLocals(block, liveness, true);
 
@@ -1838,6 +1838,23 @@
                     // Need to get probability based on current bci.
                     double probability = branchProbability();
 
+                    if (negate) {
+                        BciBlock tmpBlock = trueBlock;
+                        trueBlock = falseBlock;
+                        falseBlock = tmpBlock;
+                        probability = 1 - probability;
+                    }
+
+                    if (isNeverExecutedCode(probability)) {
+                        append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, true));
+                        appendGoto(falseBlock);
+                        return;
+                    } else if (isNeverExecutedCode(1 - probability)) {
+                        append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, false));
+                        appendGoto(trueBlock);
+                        return;
+                    }
+
                     int oldBci = stream.currentBCI();
                     int trueBlockInt = checkPositiveIntConstantPushed(trueBlock);
                     if (trueBlockInt != -1) {
@@ -1856,11 +1873,6 @@
                             if (genConditional) {
                                 ConstantNode trueValue = currentGraph.unique(ConstantNode.forInt(trueBlockInt));
                                 ConstantNode falseValue = currentGraph.unique(ConstantNode.forInt(falseBlockInt));
-                                if (negate) {
-                                    ConstantNode tmp = falseValue;
-                                    falseValue = trueValue;
-                                    trueValue = tmp;
-                                }
                                 ValueNode conditionalNode = ConditionalNode.create(condition, trueValue, falseValue);
                                 if (conditionalNode.graph() == null) {
                                     conditionalNode = currentGraph.addOrUnique(conditionalNode);
@@ -1879,10 +1891,10 @@
 
                     this.controlFlowSplit = true;
 
-                    ValueNode trueSuccessor = createBlockTarget(probability, trueBlock, frameState);
-                    ValueNode falseSuccessor = createBlockTarget(1 - probability, falseBlock, frameState);
+                    FixedNode trueSuccessor = createTarget(trueBlock, frameState);
+                    FixedNode falseSuccessor = createTarget(falseBlock, frameState);
 
-                    ValueNode ifNode = negate ? genIfNode(condition, falseSuccessor, trueSuccessor, 1 - probability) : genIfNode(condition, trueSuccessor, falseSuccessor, probability);
+                    ValueNode ifNode = genIfNode(condition, trueSuccessor, falseSuccessor, probability);
                     append(ifNode);
                 }
             }