use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class CompareCanonicalizerTest method testIntegerTestCanonicalization.
@Test
public void testIntegerTestCanonicalization() {
ValueNode result = getResult(getCanonicalizedGraph("integerTestCanonicalization1"));
assertTrue(result.isConstant() && result.asJavaConstant().asLong() == 1);
result = getResult(getCanonicalizedGraph("integerTestCanonicalization2"));
assertTrue(result.isConstant() && result.asJavaConstant().asLong() == 1);
StructuredGraph graph = getCanonicalizedGraph("integerTestCanonicalization3");
assertDeepEquals(1, graph.getNodes(ReturnNode.TYPE).count());
assertTrue(graph.getNodes(ReturnNode.TYPE).first().result() instanceof ConditionalNode);
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class HotSpotProfilingPlugin method profileIf.
@Override
public void profileIf(GraphBuilderContext builder, ResolvedJavaMethod method, int bci, LogicNode condition, int trueBranchBci, int falseBranchBci, FrameState frameState) {
assert shouldProfile(builder, method);
OptionValues options = builder.getOptions();
if (Options.ProfileBackedges.getValue(options) && (falseBranchBci <= bci || trueBranchBci <= bci)) {
boolean negate = false;
int targetBci = trueBranchBci;
if (falseBranchBci <= bci) {
assert trueBranchBci > bci;
negate = true;
targetBci = falseBranchBci;
} else {
assert trueBranchBci <= bci && falseBranchBci > bci;
}
ValueNode trueValue = builder.append(ConstantNode.forBoolean(!negate));
ValueNode falseValue = builder.append(ConstantNode.forBoolean(negate));
ConditionalNode branchCondition = builder.append(new ConditionalNode(condition, trueValue, falseValue));
ProfileNode p = builder.append(new ProfileBranchNode(method, backedgeNotifyFreqLog(options), backedgeProfilePobabilityLog(options), branchCondition, bci, targetBci));
p.setStateBefore(frameState);
}
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class ExpandLogicPhase method processConditional.
@SuppressWarnings("try")
private static void processConditional(LogicNode x, boolean xNegated, LogicNode y, boolean yNegated, ConditionalNode conditional) {
try (DebugCloseable context = conditional.withNodeSourcePosition()) {
ValueNode trueTarget = conditional.trueValue();
ValueNode falseTarget = conditional.falseValue();
Graph graph = conditional.graph();
ConditionalNode secondConditional = graph.unique(new ConditionalNode(y, yNegated ? falseTarget : trueTarget, yNegated ? trueTarget : falseTarget));
ConditionalNode firstConditional = graph.unique(new ConditionalNode(x, xNegated ? secondConditional : trueTarget, xNegated ? trueTarget : secondConditional));
conditional.replaceAndDelete(firstConditional);
}
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class ExpandLogicPhase method processNormalizeCompareNode.
private static void processNormalizeCompareNode(NormalizeCompareNode normalize) {
LogicNode equalComp;
LogicNode lessComp;
StructuredGraph graph = normalize.graph();
ValueNode x = normalize.getX();
ValueNode y = normalize.getY();
if (x.stamp(NodeView.DEFAULT) instanceof FloatStamp) {
equalComp = graph.addOrUniqueWithInputs(FloatEqualsNode.create(x, y, NodeView.DEFAULT));
lessComp = graph.addOrUniqueWithInputs(FloatLessThanNode.create(x, y, normalize.isUnorderedLess(), NodeView.DEFAULT));
} else {
equalComp = graph.addOrUniqueWithInputs(IntegerEqualsNode.create(x, y, NodeView.DEFAULT));
lessComp = graph.addOrUniqueWithInputs(IntegerLessThanNode.create(x, y, NodeView.DEFAULT));
}
Stamp stamp = normalize.stamp(NodeView.DEFAULT);
ConditionalNode equalValue = graph.unique(new ConditionalNode(equalComp, ConstantNode.forIntegerStamp(stamp, 0, graph), ConstantNode.forIntegerStamp(stamp, 1, graph)));
ConditionalNode value = graph.unique(new ConditionalNode(lessComp, ConstantNode.forIntegerStamp(stamp, -1, graph), equalValue));
normalize.replaceAtUsagesAndDelete(value);
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class LoopTransformations method updatePreLoopLimit.
private static void updatePreLoopLimit(IfNode preLimit, InductionVariable preIv, CountedLoopInfo preCounted) {
// Update the pre loops limit test
StructuredGraph graph = preLimit.graph();
LogicNode ifTest = preLimit.condition();
CompareNode compareNode = (CompareNode) ifTest;
ValueNode prePhi = preIv.valueNode();
// Make new limit one iteration
ValueNode initIv = preCounted.getStart();
ValueNode newLimit = add(graph, initIv, preIv.strideNode());
// Fetch the variable we are not replacing and configure the one we are
ValueNode ub;
if (compareNode.getX() == prePhi) {
ub = compareNode.getY();
} else if (compareNode.getY() == prePhi) {
ub = compareNode.getX();
} else {
throw GraalError.shouldNotReachHere();
}
// Re-wire the condition with the new limit
if (preIv.direction() == Direction.Up) {
compareNode.replaceFirstInput(ub, graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(newLimit, ub)), newLimit, ub)));
} else {
compareNode.replaceFirstInput(ub, graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(ub, newLimit)), newLimit, ub)));
}
}
Aggregations