< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java

Print this page

        

*** 20,38 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.loop; ! import java.util.Collection; ! import java.util.LinkedList; ! import java.util.Queue; ! import org.graalvm.compiler.core.common.calc.Condition; import org.graalvm.compiler.core.common.cfg.Loop; import org.graalvm.compiler.core.common.type.IntegerStamp; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeBitMap; import org.graalvm.compiler.graph.iterators.NodePredicate; import org.graalvm.compiler.loop.InductionVariable.Direction; import org.graalvm.compiler.nodes.AbstractBeginNode; --- 20,36 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.loop; ! import jdk.vm.ci.code.BytecodeFrame; import org.graalvm.compiler.core.common.calc.Condition; import org.graalvm.compiler.core.common.cfg.Loop; import org.graalvm.compiler.core.common.type.IntegerStamp; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; + import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeBitMap; import org.graalvm.compiler.graph.iterators.NodePredicate; import org.graalvm.compiler.loop.InductionVariable.Direction; import org.graalvm.compiler.nodes.AbstractBeginNode;
*** 70,80 **** import org.graalvm.compiler.nodes.util.GraphUtil; import org.graalvm.util.EconomicMap; import org.graalvm.util.EconomicSet; import org.graalvm.util.Equivalence; ! import jdk.vm.ci.code.BytecodeFrame; public class LoopEx { private final Loop<Block> loop; private LoopFragmentInside inside; private LoopFragmentWhole whole; --- 68,80 ---- import org.graalvm.compiler.nodes.util.GraphUtil; import org.graalvm.util.EconomicMap; import org.graalvm.util.EconomicSet; import org.graalvm.util.Equivalence; ! import java.util.Collection; ! import java.util.LinkedList; ! import java.util.Queue; public class LoopEx { private final Loop<Block> loop; private LoopFragmentInside inside; private LoopFragmentWhole whole;
*** 162,198 **** return (isCounted() ? "CountedLoop [" + counted() + "] " : "Loop ") + "(depth=" + loop().getDepth() + ") " + loopBegin(); } private class InvariantPredicate implements NodePredicate { @Override public boolean apply(Node n) { return isOutsideLoop(n); } } ! public void reassociateInvariants() { ! InvariantPredicate invariant = new InvariantPredicate(); StructuredGraph graph = loopBegin().graph(); for (BinaryArithmeticNode<?> binary : whole().nodes().filter(BinaryArithmeticNode.class)) { if (!binary.isAssociative()) { continue; } ValueNode result = BinaryArithmeticNode.reassociate(binary, invariant, binary.getX(), binary.getY()); if (result != binary) { - DebugContext debug = graph.getDebug(); - if (debug.isLogEnabled()) { - debug.log("%s : Reassociated %s into %s", graph.method().format("%H::%n"), binary, result); - } if (!result.isAlive()) { assert !result.isDeleted(); result = graph.addOrUniqueWithInputs(result); } binary.replaceAtUsages(result); GraphUtil.killWithUnusedFloatingInputs(binary); } } } public boolean detectCounted() { LoopBeginNode loopBegin = loopBegin(); FixedNode next = loopBegin.next(); --- 162,211 ---- return (isCounted() ? "CountedLoop [" + counted() + "] " : "Loop ") + "(depth=" + loop().getDepth() + ") " + loopBegin(); } private class InvariantPredicate implements NodePredicate { + private final Graph.Mark mark; + + InvariantPredicate() { + this.mark = loopBegin().graph().getMark(); + } + @Override public boolean apply(Node n) { + if (loopBegin().graph().isNew(mark, n)) { + // Newly created nodes are unknown. + return false; + } return isOutsideLoop(n); } } ! public boolean reassociateInvariants() { ! int count = 0; StructuredGraph graph = loopBegin().graph(); + InvariantPredicate invariant = new InvariantPredicate(); for (BinaryArithmeticNode<?> binary : whole().nodes().filter(BinaryArithmeticNode.class)) { if (!binary.isAssociative()) { continue; } ValueNode result = BinaryArithmeticNode.reassociate(binary, invariant, binary.getX(), binary.getY()); if (result != binary) { if (!result.isAlive()) { assert !result.isDeleted(); result = graph.addOrUniqueWithInputs(result); } + DebugContext debug = graph.getDebug(); + if (debug.isLogEnabled()) { + debug.log("%s : Reassociated %s into %s", graph.method().format("%H::%n"), binary, result); + } binary.replaceAtUsages(result); GraphUtil.killWithUnusedFloatingInputs(binary); + count++; } } + return count != 0; } public boolean detectCounted() { LoopBeginNode loopBegin = loopBegin(); FixedNode next = loopBegin.next();
< prev index next >