use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class GraphUtil method markFixedNodes.
private static void markFixedNodes(FixedNode node, EconomicSet<Node> markedNodes, EconomicMap<AbstractMergeNode, List<AbstractEndNode>> unmarkedMerges) {
NodeStack workStack = new NodeStack();
workStack.push(node);
while (!workStack.isEmpty()) {
Node fixedNode = workStack.pop();
markedNodes.add(fixedNode);
if (fixedNode instanceof AbstractMergeNode) {
unmarkedMerges.removeKey((AbstractMergeNode) fixedNode);
}
while (fixedNode instanceof FixedWithNextNode) {
fixedNode = ((FixedWithNextNode) fixedNode).next();
if (fixedNode != null) {
markedNodes.add(fixedNode);
}
}
if (fixedNode instanceof ControlSplitNode) {
for (Node successor : fixedNode.successors()) {
workStack.push(successor);
}
} else if (fixedNode instanceof AbstractEndNode) {
AbstractEndNode end = (AbstractEndNode) fixedNode;
AbstractMergeNode merge = end.merge();
if (merge != null) {
assert !markedNodes.contains(merge) || (merge instanceof LoopBeginNode && end instanceof LoopEndNode) : merge;
if (merge instanceof LoopBeginNode) {
if (end == ((LoopBeginNode) merge).forwardEnd()) {
workStack.push(merge);
continue;
}
if (markedNodes.contains(merge)) {
continue;
}
}
List<AbstractEndNode> endsSeen = unmarkedMerges.get(merge);
if (endsSeen == null) {
endsSeen = new ArrayList<>(merge.forwardEndCount());
unmarkedMerges.put(merge, endsSeen);
}
endsSeen.add(end);
if (!(end instanceof LoopEndNode) && endsSeen.size() == merge.forwardEndCount()) {
assert merge.forwardEnds().filter(n -> !markedNodes.contains(n)).isEmpty();
// all this merge's forward ends are marked: it needs to be killed
workStack.push(merge);
}
}
}
}
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class SnippetTemplate method explodeLoops.
public static void explodeLoops(final StructuredGraph snippetCopy, PhaseContext phaseContext) {
// Do any required loop explosion
boolean exploded = false;
do {
exploded = false;
ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
if (explodeLoop != null) {
// Earlier canonicalization may have removed the loop
// altogether
LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
if (loopBegin != null) {
LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
Mark mark = snippetCopy.getMark();
LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase());
new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark);
loop.deleteUnusedNodes();
}
GraphUtil.removeFixedWithUnusedInputs(explodeLoop);
exploded = true;
}
} while (exploded);
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class ExplodeLoopNode method findLoopBegin.
public LoopBeginNode findLoopBegin() {
Node currentNext = next();
ArrayList<Node> succs = new ArrayList<>();
while (!(currentNext instanceof LoopBeginNode)) {
assert currentNext != null : "cannot find loop after " + this;
for (Node n : currentNext.cfgSuccessors()) {
succs.add(n);
}
if (succs.size() == 1 && succs.get(0) != currentNext) {
currentNext = succs.get(0);
} else {
return null;
}
}
return (LoopBeginNode) currentNext;
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class IterationDirectiveTest method checkLowTierGraph.
@Override
protected boolean checkLowTierGraph(StructuredGraph graph) {
NodeIterable<LoopBeginNode> loopBeginNodes = graph.getNodes(LoopBeginNode.TYPE);
Assert.assertEquals("LoopBeginNode count", 1, loopBeginNodes.count());
LoopBeginNode loopBeginNode = loopBeginNodes.first();
Assert.assertEquals("loop frequency of " + loopBeginNode, 128, loopBeginNode.loopFrequency(), 0);
return true;
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class NodePropertiesTest method assertFrequency.
private static void assertFrequency(StructuredGraph g, int iterations) {
NodeIterable<LoopBeginNode> loopBeginNodes = g.getNodes(LoopBeginNode.TYPE);
LoopBeginNode loopBeginNode = loopBeginNodes.first();
Assert.assertEquals("loop frequency of " + loopBeginNode, iterations, loopBeginNode.loopFrequency(), 0);
}
Aggregations