use of org.graalvm.compiler.nodes.IfNode in project graal by oracle.
the class GraphKit method startIf.
/**
* Starts an if-block. This call can be followed by a call to {@link #thenPart} to start
* emitting the code executed when the condition hold; and a call to {@link #elsePart} to start
* emititng the code when the condition does not hold. It must be followed by a call to
* {@link #endIf} to close the if-block.
*
* @param condition The condition for the if-block
* @param trueProbability The estimated probability the condition is true
* @return the created {@link IfNode}.
*/
public IfNode startIf(LogicNode condition, double trueProbability) {
AbstractBeginNode thenSuccessor = graph.add(new BeginNode());
AbstractBeginNode elseSuccessor = graph.add(new BeginNode());
IfNode node = append(new IfNode(condition, thenSuccessor, elseSuccessor, trueProbability));
lastFixedNode = null;
IfStructure s = new IfStructure();
s.state = IfState.CONDITION;
s.thenPart = thenSuccessor;
s.elsePart = elseSuccessor;
pushStructure(s);
return node;
}
use of org.graalvm.compiler.nodes.IfNode in project graal by oracle.
the class AMD64NodeLIRBuilder method peephole.
@Override
protected boolean peephole(ValueNode valueNode) {
if (valueNode instanceof IntegerDivRemNode) {
AMD64ArithmeticLIRGenerator arithmeticGen = (AMD64ArithmeticLIRGenerator) gen.getArithmetic();
IntegerDivRemNode divRem = (IntegerDivRemNode) valueNode;
FixedNode node = divRem.next();
while (true) {
if (node instanceof IfNode) {
IfNode ifNode = (IfNode) node;
double probability = ifNode.getTrueSuccessorProbability();
if (probability == 1.0) {
node = ifNode.trueSuccessor();
} else if (probability == 0.0) {
node = ifNode.falseSuccessor();
} else {
break;
}
} else if (!(node instanceof FixedWithNextNode)) {
break;
}
FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) node;
if (fixedWithNextNode instanceof IntegerDivRemNode) {
IntegerDivRemNode otherDivRem = (IntegerDivRemNode) fixedWithNextNode;
if (divRem.getOp() != otherDivRem.getOp() && divRem.getType() == otherDivRem.getType()) {
if (otherDivRem.getX() == divRem.getX() && otherDivRem.getY() == divRem.getY() && !hasOperand(otherDivRem)) {
Value[] results;
switch(divRem.getType()) {
case SIGNED:
results = arithmeticGen.emitSignedDivRem(operand(divRem.getX()), operand(divRem.getY()), state((DeoptimizingNode) valueNode));
break;
case UNSIGNED:
results = arithmeticGen.emitUnsignedDivRem(operand(divRem.getX()), operand(divRem.getY()), state((DeoptimizingNode) valueNode));
break;
default:
throw GraalError.shouldNotReachHere();
}
switch(divRem.getOp()) {
case DIV:
assert otherDivRem.getOp() == Op.REM;
setResult(divRem, results[0]);
setResult(otherDivRem, results[1]);
break;
case REM:
assert otherDivRem.getOp() == Op.DIV;
setResult(divRem, results[1]);
setResult(otherDivRem, results[0]);
break;
default:
throw GraalError.shouldNotReachHere();
}
return true;
}
}
}
node = fixedWithNextNode.next();
}
}
return false;
}
use of org.graalvm.compiler.nodes.IfNode in project graal by oracle.
the class AMD64NodeMatchRules method ifCompareLogicCas.
@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
JavaConstant constant = value.asJavaConstant();
assert compare.condition() == CanonicalCondition.EQ;
if (constant != null && cas.usages().count() == 1) {
long constantValue = constant.asLong();
boolean successIsTrue;
if (constantValue == 0) {
successIsTrue = false;
} else if (constantValue == 1) {
successIsTrue = true;
} else {
return null;
}
return builder -> {
LIRKind kind = getLirKind(cas);
LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
double trueLabelProbability = root.probability(root.trueSuccessor());
Value expectedValue = operand(cas.getExpectedValue());
Value newValue = operand(cas.getNewValue());
AMD64AddressValue address = (AMD64AddressValue) operand(cas.getAddress());
Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
getLIRGeneratorTool().emitCompareAndSwapBranch(kind, address, expectedValue, newValue, condition, trueLabel, falseLabel, trueLabelProbability);
return null;
};
}
return null;
}
use of org.graalvm.compiler.nodes.IfNode in project graal by oracle.
the class InstrumentBranchesPhase method instrumentGraph.
@Override
protected void instrumentGraph(StructuredGraph graph, PhaseContext context, JavaConstant tableConstant) {
for (IfNode n : graph.getNodes().filter(IfNode.class)) {
Point p = getOrCreatePoint(n);
if (p != null) {
insertCounter(graph, context, tableConstant, n.trueSuccessor(), p.slotIndex(0));
insertCounter(graph, context, tableConstant, n.falseSuccessor(), p.slotIndex(1));
}
}
}
use of org.graalvm.compiler.nodes.IfNode in project graal by oracle.
the class ProbabilityDirectiveTest method checkLowTierGraph.
@Override
protected boolean checkLowTierGraph(StructuredGraph graph) {
NodeIterable<IfNode> ifNodes = graph.getNodes(IfNode.TYPE);
Assert.assertEquals("IfNode count", 1, ifNodes.count());
IfNode ifNode = ifNodes.first();
AbstractBeginNode oneSuccessor;
if (returnValue(ifNode.trueSuccessor()) == 1) {
oneSuccessor = ifNode.trueSuccessor();
} else {
assert returnValue(ifNode.falseSuccessor()) == 1;
oneSuccessor = ifNode.falseSuccessor();
}
Assert.assertEquals("branch probability of " + ifNode, 0.125, ifNode.probability(oneSuccessor), 0);
return true;
}
Aggregations