Mercurial > hg > truffle
changeset 21038:6868faf48f02
Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Sat, 18 Apr 2015 19:56:22 +0200 |
parents | 3fc34aafea30 |
children | 13a255e29236 |
files | graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java |
diffstat | 1 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Wed Apr 15 12:35:38 2015 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Sat Apr 18 19:56:22 2015 +0200 @@ -222,6 +222,7 @@ node.replaceAtPredecessor(deopt); GraphUtil.killCFG(node); } + return true; }); } } @@ -237,6 +238,7 @@ if (survivingSuccessor instanceof BeginNode) { undoOperations.add(() -> ((BeginNode) survivingSuccessor).trySimplify()); } + return true; }); } @@ -276,12 +278,11 @@ } } - private boolean rewireGuards(ValueNode guard, boolean result, BiConsumer<ValueNode, Boolean> rewireGuardFunction) { + private boolean rewireGuards(ValueNode guard, boolean result, GuardRewirer rewireGuardFunction) { assert guard instanceof GuardingNode; metricStampsFound.increment(); ValueNode proxiedGuard = proxyGuard(guard); - rewireGuardFunction.accept(proxiedGuard, result); - return true; + return rewireGuardFunction.rewire(proxiedGuard, result); } private ValueNode proxyGuard(ValueNode guard) { @@ -306,7 +307,18 @@ return proxiedGuard; } - private boolean tryProofCondition(LogicNode node, BiConsumer<ValueNode, Boolean> rewireGuardFunction) { + @FunctionalInterface + private interface GuardRewirer { + /** + * Called if the condition could be proven to have a constant value ({@code result}) + * under {@code guard}. + * + * Return whether a transformation could be applied. + */ + boolean rewire(ValueNode guard, boolean result); + } + + private boolean tryProofCondition(LogicNode node, GuardRewirer rewireGuardFunction) { for (InfoElement infoElement : getInfoElements(node)) { Stamp stamp = infoElement.getStamp(); JavaConstant constant = (JavaConstant) stamp.asConstant(); @@ -352,14 +364,15 @@ } else if (node instanceof ShortCircuitOrNode) { final ShortCircuitOrNode shortCircuitOrNode = (ShortCircuitOrNode) node; if (this.loopExits.isEmpty()) { - tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> { + return tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> { if (result == !shortCircuitOrNode.isXNegated()) { - rewireGuards(guard, result, rewireGuardFunction); + return rewireGuards(guard, result, rewireGuardFunction); } else { - tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> { + return tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> { if (innerGuard == guard) { - rewireGuards(guard, shortCircuitOrNode.isYNegated() ? !innerResult : innerResult, rewireGuardFunction); + return rewireGuards(guard, shortCircuitOrNode.isYNegated() ? !innerResult : innerResult, rewireGuardFunction); } + return false; }); } }); @@ -395,6 +408,7 @@ node.replaceAtUsages(valueAnchor); node.graph().replaceFixedWithFixed(node, valueAnchor); } + return true; }); } @@ -409,6 +423,7 @@ beginNode.setNext(deopt); GraphUtil.killCFG(next); } + return true; })) { registerNewCondition(node.condition(), node.isNegated(), node, undoOperations); } @@ -426,6 +441,7 @@ node.replaceAtPredecessor(deopt); GraphUtil.killCFG(node); } + return true; })) { registerNewCondition(node.condition(), node.isNegated(), node, undoOperations); }