Mercurial > hg > graal-compiler
changeset 22909:5ce3e8996c83
Add unifying DeoptimizingGuard interface for AbstractFixedGuardNode and GuardNode
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GuardEliminationCornerCasesTest.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GuardEliminationCornerCasesTest.java Thu Oct 29 12:23:07 2015 -0700 @@ -94,7 +94,7 @@ for (Node n : graph.getNodes()) { if (n instanceof GuardNode) { GuardNode guardNode = (GuardNode) n; - LogicNode condition = guardNode.condition(); + LogicNode condition = guardNode.getCondition(); if (condition instanceof InstanceOfNode) { InstanceOfNode instanceOfNode = (InstanceOfNode) condition; if (instanceOfNode.getValue() instanceof ValueProxy) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractFixedGuardNode.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractFixedGuardNode.java Thu Oct 29 12:23:07 2015 -0700 @@ -37,7 +37,7 @@ import com.oracle.graal.nodes.util.GraphUtil; @NodeInfo -public abstract class AbstractFixedGuardNode extends DeoptimizingFixedWithNextNode implements Simplifiable, GuardingNode { +public abstract class AbstractFixedGuardNode extends DeoptimizingFixedWithNextNode implements Simplifiable, GuardingNode, DeoptimizingGuard { public static final NodeClass<AbstractFixedGuardNode> TYPE = NodeClass.create(AbstractFixedGuardNode.class); @Input(InputType.Condition) protected LogicNode condition; @@ -46,13 +46,18 @@ protected JavaConstant speculation; protected boolean negated; - public LogicNode condition() { + public LogicNode getCondition() { return condition; } - public void setCondition(LogicNode x) { + public LogicNode condition() { + return getCondition(); + } + + public void setCondition(LogicNode x, boolean negated) { updateUsages(condition, x); condition = x; + this.negated = negated; } protected AbstractFixedGuardNode(NodeClass<? extends AbstractFixedGuardNode> c, LogicNode condition, DeoptimizationReason deoptReason, DeoptimizationAction action, JavaConstant speculation, @@ -94,8 +99,7 @@ public void simplify(SimplifierTool tool) { while (condition instanceof LogicNegationNode) { LogicNegationNode negation = (LogicNegationNode) condition; - setCondition(negation.getValue()); - negated = !negated; + setCondition(negation.getValue(), !negated); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/DeoptimizingGuard.java Thu Oct 29 12:23:07 2015 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.nodes; + +import jdk.vm.ci.meta.DeoptimizationAction; +import jdk.vm.ci.meta.DeoptimizationReason; +import jdk.vm.ci.meta.JavaConstant; + +import com.oracle.graal.graph.NodeInterface; + +/** + * Shared interface to capture core methods of {@link AbstractFixedGuardNode} and {@link GuardNode}. + * + */ +public interface DeoptimizingGuard extends NodeInterface { + + LogicNode getCondition(); + + void setCondition(LogicNode x, boolean negated); + + DeoptimizationReason getReason(); + + DeoptimizationAction getAction(); + + JavaConstant getSpeculation(); + + boolean isNegated(); +}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java Thu Oct 29 12:23:07 2015 -0700 @@ -55,8 +55,8 @@ public void simplify(SimplifierTool tool) { super.simplify(tool); - if (condition() instanceof LogicConstantNode) { - LogicConstantNode c = (LogicConstantNode) condition(); + if (getCondition() instanceof LogicConstantNode) { + LogicConstantNode c = (LogicConstantNode) getCondition(); if (c.getValue() == isNegated()) { FixedNode currentNext = this.next(); if (currentNext != null) { @@ -69,8 +69,8 @@ } this.replaceAtUsages(null); graph().removeFixed(this); - } else if (condition() instanceof ShortCircuitOrNode) { - ShortCircuitOrNode shortCircuitOr = (ShortCircuitOrNode) condition(); + } else if (getCondition() instanceof ShortCircuitOrNode) { + ShortCircuitOrNode shortCircuitOr = (ShortCircuitOrNode) getCondition(); if (isNegated() && hasNoUsages()) { graph().addAfterFixed(this, graph().add(new FixedGuardNode(shortCircuitOr.getY(), getReason(), getAction(), getSpeculation(), !shortCircuitOr.isYNegated()))); graph().replaceFixedWithFixed(this, graph().add(new FixedGuardNode(shortCircuitOr.getX(), getReason(), getAction(), getSpeculation(), !shortCircuitOr.isXNegated()))); @@ -90,7 +90,7 @@ * case. */ if (getAction() != DeoptimizationAction.None || getReason() != DeoptimizationReason.RuntimeConstraint) { - ValueNode guard = tool.createGuard(this, condition(), getReason(), getAction(), getSpeculation(), isNegated()).asNode(); + ValueNode guard = tool.createGuard(this, getCondition(), getReason(), getAction(), getSpeculation(), isNegated()).asNode(); this.replaceAtUsages(guard); ValueAnchorNode newAnchor = graph().add(new ValueAnchorNode(guard.asNode())); graph().replaceFixedWithFixed(this, newAnchor);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Thu Oct 29 12:23:07 2015 -0700 @@ -50,7 +50,7 @@ * control flow would have reached the guarded node (without taking exceptions into account). */ @NodeInfo(nameTemplate = "Guard(!={p#negated}) {p#reason/s}", allowedUsageTypes = {InputType.Guard}) -public class GuardNode extends FloatingAnchoredNode implements Canonicalizable, GuardingNode { +public class GuardNode extends FloatingAnchoredNode implements Canonicalizable, GuardingNode, DeoptimizingGuard { public static final NodeClass<GuardNode> TYPE = NodeClass.create(GuardNode.class); @Input(InputType.Condition) protected LogicNode condition; @@ -75,19 +75,25 @@ /** * The instruction that produces the tested boolean value. */ - public LogicNode condition() { + public LogicNode getCondition() { return condition; } + public void setCondition(LogicNode x, boolean negated) { + updateUsages(condition, x); + condition = x; + this.negated = negated; + } + public boolean isNegated() { return negated; } - public DeoptimizationReason reason() { + public DeoptimizationReason getReason() { return reason; } - public DeoptimizationAction action() { + public DeoptimizationAction getAction() { return action; } @@ -110,12 +116,12 @@ @Override public Node canonical(CanonicalizerTool tool) { - if (condition() instanceof LogicNegationNode) { - LogicNegationNode negation = (LogicNegationNode) condition(); + if (getCondition() instanceof LogicNegationNode) { + LogicNegationNode negation = (LogicNegationNode) getCondition(); return new GuardNode(negation.getValue(), getAnchor(), reason, action, !negated, speculation); } - if (condition() instanceof LogicConstantNode) { - LogicConstantNode c = (LogicConstantNode) condition(); + if (getCondition() instanceof LogicConstantNode) { + LogicConstantNode c = (LogicConstantNode) getCondition(); if (c.getValue() != negated) { return null; }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Thu Oct 29 12:23:07 2015 -0700 @@ -83,7 +83,7 @@ if (currentNext.getGuard() == anchored) { GraphUtil.removeFixedWithUnusedInputs(this); return; - } else if (currentNext.getGuard() == null && anchored instanceof GuardNode && ((GuardNode) anchored).condition() instanceof IsNullNode) { + } else if (currentNext.getGuard() == null && anchored instanceof GuardNode && ((GuardNode) anchored).getCondition() instanceof IsNullNode) { // coalesce null check guards into subsequent read/write currentNext.setGuard((GuardingNode) anchored); tool.addToWorkList(next());
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Thu Oct 29 12:23:07 2015 -0700 @@ -487,12 +487,12 @@ } private GuardedStamp computeGuardedStamp(GuardNode guard) { - if (guard.condition() instanceof IntegerBelowNode) { + if (guard.getCondition() instanceof IntegerBelowNode) { if (guard.isNegated()) { // Not sure how to reason about negated guards return null; } - IntegerBelowNode below = (IntegerBelowNode) guard.condition(); + IntegerBelowNode below = (IntegerBelowNode) guard.getCondition(); if (below.getX().getStackKind() == JavaKind.Int && below.getX().isConstant() && !below.getY().isConstant()) { Stamp stamp = StampTool.unsignedCompare(below.getX().stamp(), below.getY().stamp()); if (stamp != null) { @@ -543,8 +543,8 @@ } GuardNode existingGuard = null; - if (guard.condition() instanceof IntegerBelowNode) { - IntegerBelowNode below = (IntegerBelowNode) guard.condition(); + if (guard.getCondition() instanceof IntegerBelowNode) { + IntegerBelowNode below = (IntegerBelowNode) guard.getCondition(); IntegerStamp xStamp = (IntegerStamp) below.getX().stamp(); IntegerStamp yStamp = (IntegerStamp) below.getY().stamp(); GuardedStamp cstamp = state.valueConstraints.get(below.getX()); @@ -566,22 +566,22 @@ if (xStamp.isPositive() && xStamp.upperBound() < yStamp.lowerBound()) { // Proven true existingGuard = cstamp.getGuard(); - Debug.log("existing guard %s %1s proves %1s", existingGuard, existingGuard.condition(), guard.condition()); + Debug.log("existing guard %s %1s proves %1s", existingGuard, existingGuard.getCondition(), guard.getCondition()); } else if (xStamp.isStrictlyNegative() || xStamp.lowerBound() >= yStamp.upperBound()) { // An earlier guard proves that this will always fail but it's probably // not worth trying to use it. } } } - } else if (guard.condition() instanceof IntegerEqualsNode && guard.isNegated()) { - IntegerEqualsNode equals = (IntegerEqualsNode) guard.condition(); + } else if (guard.getCondition() instanceof IntegerEqualsNode && guard.isNegated()) { + IntegerEqualsNode equals = (IntegerEqualsNode) guard.getCondition(); GuardedStamp cstamp = state.valueConstraints.get(equals.getY()); if (cstamp != null && equals.getX().isConstant()) { IntegerStamp stamp = (IntegerStamp) cstamp.getStamp(); if (!stamp.contains(equals.getX().asJavaConstant().asLong())) { // x != n is true if n is outside the range of the stamp existingGuard = cstamp.getGuard(); - Debug.log("existing guard %s %1s proves !%1s", existingGuard, existingGuard.condition(), guard.condition()); + Debug.log("existing guard %s %1s proves !%1s", existingGuard, existingGuard.getCondition(), guard.getCondition()); } } } @@ -595,7 +595,7 @@ } private boolean tryReplaceWithExistingGuard(GuardNode guard) { - GuardingNode existingGuard = guard.isNegated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); + GuardingNode existingGuard = guard.isNegated() ? state.falseConditions.get(guard.getCondition()) : state.trueConditions.get(guard.getCondition()); if (existingGuard != null && existingGuard != guard) { eliminateGuard(guard, existingGuard); return true; @@ -617,7 +617,7 @@ // information Stamp result = conditional.getStamp().join(other.getStamp()); if (result == conditional.getStamp()) { - Debug.log("%1s overrides existing value %1s", guard.condition(), other.getGuard().condition()); + Debug.log("%1s overrides existing value %1s", guard.getCondition(), other.getGuard().getCondition()); state.valueConstraints.put(conditional.getValue(), conditional); } else if (result == other.getStamp()) { // existing type constraint is best @@ -879,7 +879,7 @@ // to see if they can be deleted using type constraints. for (GuardNode guard : begin.guards().snapshot()) { if (provers.contains(guard) || !(tryReplaceWithExistingGuard(guard) || testImpliedGuard(guard))) { - registerCondition(!guard.isNegated(), guard.condition(), guard); + registerCondition(!guard.isNegated(), guard.getCondition(), guard); } } assert assertImpliedGuard(provers);
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Thu Oct 29 12:23:07 2015 -0700 @@ -576,11 +576,11 @@ } private void processGuard(GuardNode node, List<Runnable> undoOperations) { - if (!tryProofCondition(node.condition(), (guard, result) -> { + if (!tryProofCondition(node.getCondition(), (guard, result) -> { if (result != node.isNegated()) { node.replaceAndDelete(guard); } else { - DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.action(), node.reason(), node.getSpeculation())); + DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.getAction(), node.getReason(), node.getSpeculation())); AbstractBeginNode beginNode = (AbstractBeginNode) node.getAnchor(); FixedNode next = beginNode.next(); beginNode.setNext(deopt); @@ -588,7 +588,7 @@ } return true; })) { - registerNewCondition(node.condition(), node.isNegated(), node, undoOperations); + registerNewCondition(node.getCondition(), node.isNegated(), node, undoOperations); } }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java Thu Oct 29 12:23:07 2015 -0700 @@ -173,7 +173,7 @@ PiNode piNode = (PiNode) guard; guardNode = (GuardNode) piNode.getGuard(); } - LogicNode condition = guardNode.condition(); + LogicNode condition = guardNode.getCondition(); guardNode.replaceAndDelete(fixedAccess); if (condition.hasNoUsages()) { GraphUtil.killWithUnusedFloatingInputs(condition); @@ -184,8 +184,8 @@ private void processGuard(Node node) { GuardNode guard = (GuardNode) node; - if (guard.isNegated() && guard.condition() instanceof IsNullNode && (guard.getSpeculation() == null || guard.getSpeculation().equals(JavaConstant.NULL_POINTER))) { - ValueNode obj = ((IsNullNode) guard.condition()).getValue(); + if (guard.isNegated() && guard.getCondition() instanceof IsNullNode && (guard.getSpeculation() == null || guard.getSpeculation().equals(JavaConstant.NULL_POINTER))) { + ValueNode obj = ((IsNullNode) guard.getCondition()).getValue(); nullGuarded.put(obj, guard); } } @@ -228,7 +228,7 @@ AbstractBeginNode fastPath = graph.add(new BeginNode()); @SuppressWarnings("deprecation") int debugId = useGuardIdAsDebugId ? guard.getId() : DeoptimizeNode.DEFAULT_DEBUG_ID; - DeoptimizeNode deopt = graph.add(new DeoptimizeNode(guard.action(), guard.reason(), debugId, guard.getSpeculation(), null)); + DeoptimizeNode deopt = graph.add(new DeoptimizeNode(guard.getAction(), guard.getReason(), debugId, guard.getSpeculation(), null)); AbstractBeginNode deoptBranch = BeginNode.begin(deopt); AbstractBeginNode trueSuccessor; AbstractBeginNode falseSuccessor; @@ -240,7 +240,7 @@ trueSuccessor = fastPath; falseSuccessor = deoptBranch; } - IfNode ifNode = graph.add(new IfNode(guard.condition(), trueSuccessor, falseSuccessor, trueSuccessor == fastPath ? 1 : 0)); + IfNode ifNode = graph.add(new IfNode(guard.getCondition(), trueSuccessor, falseSuccessor, trueSuccessor == fastPath ? 1 : 0)); guard.replaceAndDelete(fastPath); insert(ifNode, fastPath); }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/OptimizeGuardAnchorsPhase.java Thu Oct 29 12:22:45 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/OptimizeGuardAnchorsPhase.java Thu Oct 29 12:23:07 2015 -0700 @@ -107,14 +107,14 @@ AbstractBeginNode successor = findMinimumUsagesSuccessor(controlSplit); int successorCount = controlSplit.successors().count(); for (GuardNode guard : successor.guards().snapshot()) { - if (guard.isDeleted() || guard.condition().getUsageCount() < successorCount) { + if (guard.isDeleted() || guard.getCondition().getUsageCount() < successorCount) { continue; } List<GuardNode> otherGuards = new ArrayList<>(successorCount - 1); HashSet<Node> successorsWithoutGuards = new HashSet<>(controlSplit.successors().count()); controlSplit.successors().snapshotTo(successorsWithoutGuards); successorsWithoutGuards.remove(guard.getAnchor()); - for (GuardNode conditonGuard : guard.condition().usages().filter(GuardNode.class)) { + for (GuardNode conditonGuard : guard.getCondition().usages().filter(GuardNode.class)) { if (conditonGuard != guard) { AnchoringNode conditionGuardAnchor = conditonGuard.getAnchor(); if (conditionGuardAnchor.asNode().predecessor() == controlSplit && compatibleGuards(guard, conditonGuard)) { @@ -127,7 +127,7 @@ if (successorsWithoutGuards.isEmpty()) { assert otherGuards.size() >= successorCount - 1; AbstractBeginNode anchor = computeOptimalAnchor(cfg.get(), AbstractBeginNode.prevBegin(controlSplit)); - GuardNode newGuard = controlSplit.graph().unique(new GuardNode(guard.condition(), anchor, guard.reason(), guard.action(), guard.isNegated(), guard.getSpeculation())); + GuardNode newGuard = controlSplit.graph().unique(new GuardNode(guard.getCondition(), anchor, guard.getReason(), guard.getAction(), guard.isNegated(), guard.getSpeculation())); for (GuardNode otherGuard : otherGuards) { otherGuard.replaceAndDelete(newGuard); } @@ -139,7 +139,7 @@ } private static boolean compatibleGuards(GuardNode guard, GuardNode conditonGuard) { - return conditonGuard.isNegated() == guard.isNegated() && conditonGuard.action() == guard.action() && conditonGuard.reason() == guard.reason() && + return conditonGuard.isNegated() == guard.isNegated() && conditonGuard.getAction() == guard.getAction() && conditonGuard.getReason() == guard.getReason() && conditonGuard.getSpeculation().equals(guard.getSpeculation()); }