< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java
Print this page
@@ -74,19 +74,18 @@
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.debug.ControlFlowAnchored;
import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
import org.graalvm.compiler.nodes.util.GraphUtil;
-import jdk.vm.ci.code.BytecodeFrame;
-
public class LoopEx {
private final Loop<Block> loop;
private LoopFragmentInside inside;
private LoopFragmentWhole whole;
private CountedLoopInfo counted;
private LoopsData data;
private EconomicMap<Node, InductionVariable> ivs;
+ private boolean countedLoopChecked;
LoopEx(Loop<Block> loop, LoopsData data) {
this.loop = loop;
this.data = data;
}
@@ -141,14 +140,16 @@
public FixedNode entryPoint() {
return loopBegin().forwardEnd();
}
public boolean isCounted() {
+ assert countedLoopChecked;
return counted != null;
}
public CountedLoopInfo counted() {
+ assert countedLoopChecked;
return counted;
}
public LoopEx parent() {
if (loop.getParent() == null) {
@@ -209,20 +210,24 @@
}
return count != 0;
}
public boolean detectCounted() {
+ if (countedLoopChecked) {
+ return isCounted();
+ }
+ countedLoopChecked = true;
LoopBeginNode loopBegin = loopBegin();
FixedNode next = loopBegin.next();
while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
next = ((FixedWithNextNode) next).next();
}
if (next instanceof IfNode) {
IfNode ifNode = (IfNode) next;
boolean negated = false;
- if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
- if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
+ if (!isCfgLoopExit(ifNode.falseSuccessor())) {
+ if (!isCfgLoopExit(ifNode.trueSuccessor())) {
return false;
}
negated = true;
}
LogicNode ifTest = ifNode.condition();
@@ -299,18 +304,23 @@
if (iv.direction() != Direction.Down) {
return false;
}
break;
default:
- throw GraalError.shouldNotReachHere();
+ throw GraalError.shouldNotReachHere(condition.toString());
}
counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
return true;
}
return false;
}
+ private boolean isCfgLoopExit(AbstractBeginNode begin) {
+ Block block = data.getCFG().blockFor(begin);
+ return loop.getDepth() > block.getLoopDepth() || loop.isNaturalExit(block);
+ }
+
public LoopsData loopsData() {
return data;
}
public void nodesInLoopBranch(NodeBitMap branchNodes, AbstractBeginNode branch) {
@@ -319,11 +329,11 @@
Queue<Block> work = new LinkedList<>();
ControlFlowGraph cfg = loopsData().getCFG();
work.add(cfg.blockFor(branch));
while (!work.isEmpty()) {
Block b = work.remove();
- if (loop().getExits().contains(b)) {
+ if (loop().isLoopExit(b)) {
assert !exits.contains(b.getBeginNode());
exits.add(b.getBeginNode());
} else if (blocks.add(b.getBeginNode())) {
Block d = b.getDominatedSibling();
while (d != null) {
@@ -463,11 +473,11 @@
if (node instanceof ControlFlowAnchored) {
return false;
}
if (node instanceof FrameState) {
FrameState frameState = (FrameState) node;
- if (frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI || frameState.bci == BytecodeFrame.UNWIND_BCI) {
+ if (frameState.isExceptionHandlingBCI()) {
return false;
}
}
}
return true;
< prev index next >