use of org.graalvm.compiler.nodes.AbstractMergeNode in project graal by oracle.
the class ConvertDeoptimizeToGuardPhase method propagateFixed.
@SuppressWarnings("try")
private void propagateFixed(FixedNode from, StaticDeoptimizingNode deopt, LoweringProvider loweringProvider) {
Node current = from;
while (current != null) {
if (GraalOptions.GuardPriorities.getValue(from.getOptions()) && current instanceof FixedGuardNode) {
FixedGuardNode otherGuard = (FixedGuardNode) current;
if (otherGuard.computePriority().isHigherPriorityThan(deopt.computePriority())) {
moveAsDeoptAfter(otherGuard, deopt);
return;
}
} else if (current instanceof AbstractBeginNode) {
if (current instanceof AbstractMergeNode) {
AbstractMergeNode mergeNode = (AbstractMergeNode) current;
FixedNode next = mergeNode.next();
while (mergeNode.isAlive()) {
AbstractEndNode end = mergeNode.forwardEnds().first();
propagateFixed(end, deopt, loweringProvider);
}
assert next.isAlive();
propagateFixed(next, deopt, loweringProvider);
return;
} else if (current.predecessor() instanceof IfNode) {
IfNode ifNode = (IfNode) current.predecessor();
// Prioritize the source position of the IfNode
try (DebugCloseable closable = ifNode.withNodeSourcePosition()) {
StructuredGraph graph = ifNode.graph();
LogicNode conditionNode = ifNode.condition();
boolean negateGuardCondition = current == ifNode.trueSuccessor();
FixedGuardNode guard = graph.add(new FixedGuardNode(conditionNode, deopt.getReason(), deopt.getAction(), deopt.getSpeculation(), negateGuardCondition));
FixedWithNextNode pred = (FixedWithNextNode) ifNode.predecessor();
AbstractBeginNode survivingSuccessor;
if (negateGuardCondition) {
survivingSuccessor = ifNode.falseSuccessor();
} else {
survivingSuccessor = ifNode.trueSuccessor();
}
graph.removeSplitPropagate(ifNode, survivingSuccessor);
Node newGuard = guard;
if (survivingSuccessor instanceof LoopExitNode) {
newGuard = ProxyNode.forGuard(guard, (LoopExitNode) survivingSuccessor, graph);
}
survivingSuccessor.replaceAtUsages(InputType.Guard, newGuard);
graph.getDebug().log("Converting deopt on %-5s branch of %s to guard for remaining branch %s.", negateGuardCondition, ifNode, survivingSuccessor);
FixedNode next = pred.next();
pred.setNext(guard);
guard.setNext(next);
SimplifierTool simplifierTool = GraphUtil.getDefaultSimplifier(null, null, null, false, graph.getAssumptions(), graph.getOptions(), loweringProvider);
survivingSuccessor.simplify(simplifierTool);
return;
}
} else if (current.predecessor() == null || current.predecessor() instanceof ControlSplitNode) {
assert current.predecessor() != null || (current instanceof StartNode && current == ((AbstractBeginNode) current).graph().start());
moveAsDeoptAfter((AbstractBeginNode) current, deopt);
return;
}
}
current = current.predecessor();
}
}
use of org.graalvm.compiler.nodes.AbstractMergeNode in project graal by oracle.
the class ExpandLogicPhase method processIf.
@SuppressWarnings("try")
private static void processIf(LogicNode x, boolean xNegated, LogicNode y, boolean yNegated, IfNode ifNode, double shortCircuitProbability) {
try (DebugCloseable context = ifNode.withNodeSourcePosition()) {
/*
* this method splits an IfNode, which has a ShortCircuitOrNode as its condition, into
* two separate IfNodes: if(X) and if(Y)
*
* for computing the probabilities P(X) and P(Y), we use two different approaches. The
* first one assumes that the shortCircuitProbability and the probability on the IfNode
* were created with each other in mind. If this assumption does not hold, we fall back
* to another mechanism for computing the probabilities.
*/
AbstractBeginNode trueTarget = ifNode.trueSuccessor();
AbstractBeginNode falseTarget = ifNode.falseSuccessor();
// 1st approach
// assumption: P(originalIf.trueSuccessor) == P(X) + ((1 - P(X)) * P(Y))
double firstIfTrueProbability = shortCircuitProbability;
double secondIfTrueProbability = sanitizeProbability((ifNode.getTrueSuccessorProbability() - shortCircuitProbability) / (1 - shortCircuitProbability));
double expectedOriginalIfTrueProbability = firstIfTrueProbability + (1 - firstIfTrueProbability) * secondIfTrueProbability;
if (!doubleEquals(ifNode.getTrueSuccessorProbability(), expectedOriginalIfTrueProbability)) {
/*
* 2nd approach
*
* the assumption above did not hold, so we either used an artificial probability as
* shortCircuitProbability or the ShortCircuitOrNode was moved to some other IfNode.
*
* so, we distribute the if's trueSuccessorProbability between the newly generated
* if nodes according to the shortCircuitProbability. the following invariant is
* always true in this case: P(originalIf.trueSuccessor) == P(X) + ((1 - P(X)) *
* P(Y))
*/
firstIfTrueProbability = ifNode.getTrueSuccessorProbability() * shortCircuitProbability;
secondIfTrueProbability = sanitizeProbability(1 - (ifNode.probability(falseTarget) / (1 - firstIfTrueProbability)));
}
ifNode.clearSuccessors();
Graph graph = ifNode.graph();
AbstractMergeNode trueTargetMerge = graph.add(new MergeNode());
trueTargetMerge.setNext(trueTarget);
EndNode firstTrueEnd = graph.add(new EndNode());
EndNode secondTrueEnd = graph.add(new EndNode());
trueTargetMerge.addForwardEnd(firstTrueEnd);
trueTargetMerge.addForwardEnd(secondTrueEnd);
AbstractBeginNode firstTrueTarget = BeginNode.begin(firstTrueEnd);
AbstractBeginNode secondTrueTarget = BeginNode.begin(secondTrueEnd);
if (yNegated) {
secondIfTrueProbability = 1.0 - secondIfTrueProbability;
}
if (xNegated) {
firstIfTrueProbability = 1.0 - firstIfTrueProbability;
}
AbstractBeginNode secondIf = BeginNode.begin(graph.add(new IfNode(y, yNegated ? falseTarget : secondTrueTarget, yNegated ? secondTrueTarget : falseTarget, secondIfTrueProbability)));
IfNode firstIf = graph.add(new IfNode(x, xNegated ? secondIf : firstTrueTarget, xNegated ? firstTrueTarget : secondIf, firstIfTrueProbability));
ifNode.replaceAtPredecessor(firstIf);
ifNode.safeDelete();
}
}
use of org.graalvm.compiler.nodes.AbstractMergeNode in project graal by oracle.
the class TypeSystemTest method outputNode.
private static void outputNode(Node node) {
TTY.print(" " + node + " (usage count: " + node.getUsageCount() + ") (inputs:");
for (Node input : node.inputs()) {
TTY.print(" " + input.toString(Verbosity.Id));
}
TTY.println(")");
if (node instanceof AbstractMergeNode) {
for (PhiNode phi : ((AbstractMergeNode) node).phis()) {
outputNode(phi);
}
}
}
use of org.graalvm.compiler.nodes.AbstractMergeNode in project graal by oracle.
the class NodeLIRBuilder method visitEndNode.
@Override
public void visitEndNode(AbstractEndNode end) {
AbstractMergeNode merge = end.merge();
JumpOp jump = newJumpOp(getLIRBlock(merge));
jump.setPhiValues(createPhiOut(merge, end));
append(jump);
}
use of org.graalvm.compiler.nodes.AbstractMergeNode in project graal by oracle.
the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.
@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
prepareGraph(snippet, false);
for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
merge.setStateAfter(null);
}
new DeadCodeEliminationPhase().apply(graph);
new CanonicalizerPhase().apply(graph, context);
try {
Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
double probabilitySum = 0;
int materializeCount = 0;
for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
materializeCount += materialize.getVirtualObjects().size();
}
Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
for (Node node : graph.getNodes()) {
for (Class<? extends Node> clazz : invalidNodeClasses) {
Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
}
}
} catch (AssertionError e) {
TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
throw e;
}
}
Aggregations