use of org.graalvm.compiler.nodes.GuardNode in project graal by oracle.
the class GuardPrioritiesTest method growingTest.
@Test
public void growingTest() {
assumeTrue("GuardPriorities must be turned one", GraalOptions.GuardPriorities.getValue(getInitialOptions()));
StructuredGraph graph = prepareGraph("growing");
NodeIterable<GuardNode> guards = graph.getNodes(GuardNode.TYPE).filter(n -> n.inputs().filter(i -> i instanceof IntegerLowerThanNode).isNotEmpty());
assertThat(guards, isNotEmpty());
assumeThat(guards, hasCount(2));
Iterator<GuardNode> iterator = guards.iterator();
GuardNode g1 = iterator.next();
GuardNode g2 = iterator.next();
assertTrue("There should be one guard with speculation, the other one without", g1.getSpeculation().isNull() ^ g2.getSpeculation().isNull());
GuardNode withSpeculation = g1.getSpeculation().isNull() ? g2 : g1;
GuardNode withoutSpeculation = g1.getSpeculation().isNull() ? g1 : g2;
assertOrderedAfterSchedule(graph, SchedulePhase.SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER, withSpeculation, withoutSpeculation);
}
use of org.graalvm.compiler.nodes.GuardNode in project graal by oracle.
the class ConditionalEliminationTest14 method test1.
@Test
public void test1() {
StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext context = new PhaseContext(getProviders());
/* Convert the LoadIndexNode to ReadNode with floating guards. */
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
/* Convert the ReadNode to FloatingReadNode. */
new FloatingReadPhase().apply(graph);
/* Apply the phase that we want to test. */
new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
LogicNode condition = boundsChecks.first().getCondition();
Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
}
use of org.graalvm.compiler.nodes.GuardNode in project graal by oracle.
the class GraphUtil method killWithUnusedFloatingInputs.
public static void killWithUnusedFloatingInputs(Node node, boolean mayKillGuard) {
assert checkKill(node, mayKillGuard);
node.markDeleted();
outer: for (Node in : node.inputs()) {
if (in.isAlive()) {
in.removeUsage(node);
if (in.hasNoUsages()) {
node.maybeNotifyZeroUsages(in);
}
if (isFloatingNode(in)) {
if (in.hasNoUsages()) {
if (in instanceof GuardNode) {
// Guard nodes are only killed if their anchor dies.
} else {
killWithUnusedFloatingInputs(in);
}
} else if (in instanceof PhiNode) {
for (Node use : in.usages()) {
if (use != in) {
continue outer;
}
}
in.replaceAtUsages(null);
killWithUnusedFloatingInputs(in);
}
}
}
}
}
use of org.graalvm.compiler.nodes.GuardNode in project graal by oracle.
the class GraphUtil method killCFG.
@SuppressWarnings("try")
public static void killCFG(FixedNode node) {
DebugContext debug = node.getDebug();
try (DebugContext.Scope scope = debug.scope("KillCFG", node)) {
EconomicSet<Node> unusedNodes = null;
EconomicSet<Node> unsafeNodes = null;
Graph.NodeEventScope nodeEventScope = null;
OptionValues options = node.getOptions();
if (Graph.Options.VerifyGraalGraphEdges.getValue(options)) {
unsafeNodes = collectUnsafeNodes(node.graph());
}
if (GraphUtil.Options.VerifyKillCFGUnusedNodes.getValue(options)) {
EconomicSet<Node> collectedUnusedNodes = unusedNodes = EconomicSet.create(Equivalence.IDENTITY);
nodeEventScope = node.graph().trackNodeEvents(new Graph.NodeEventListener() {
@Override
public void changed(Graph.NodeEvent e, Node n) {
if (e == Graph.NodeEvent.ZERO_USAGES && isFloatingNode(n) && !(n instanceof GuardNode)) {
collectedUnusedNodes.add(n);
}
}
});
}
debug.dump(DebugContext.VERY_DETAILED_LEVEL, node.graph(), "Before killCFG %s", node);
killCFGInner(node);
debug.dump(DebugContext.VERY_DETAILED_LEVEL, node.graph(), "After killCFG %s", node);
if (Graph.Options.VerifyGraalGraphEdges.getValue(options)) {
EconomicSet<Node> newUnsafeNodes = collectUnsafeNodes(node.graph());
newUnsafeNodes.removeAll(unsafeNodes);
assert newUnsafeNodes.isEmpty() : "New unsafe nodes: " + newUnsafeNodes;
}
if (GraphUtil.Options.VerifyKillCFGUnusedNodes.getValue(options)) {
nodeEventScope.close();
Iterator<Node> iterator = unusedNodes.iterator();
while (iterator.hasNext()) {
Node curNode = iterator.next();
if (curNode.isDeleted()) {
iterator.remove();
}
}
assert unusedNodes.isEmpty() : "New unused nodes: " + unusedNodes;
}
} catch (Throwable t) {
throw debug.handle(t);
}
}
Aggregations