Search in sources :

Example 16 with IfNode

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;
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 17 with IfNode

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;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) IntegerDivRemNode(org.graalvm.compiler.nodes.calc.IntegerDivRemNode) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 18 with IfNode

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;
}
Also used : OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize) AMD64RMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp) AVXOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AVXOp) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) LabelRef(org.graalvm.compiler.lir.LabelRef) UnsignedRightShiftNode(org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode) SUB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.SUB) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) NumUtil(org.graalvm.compiler.core.common.NumUtil) IfNode(org.graalvm.compiler.nodes.IfNode) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) NodeView(org.graalvm.compiler.nodes.NodeView) LIRLowerableAccess(org.graalvm.compiler.nodes.memory.LIRLowerableAccess) BranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.BranchOp) MOVSX(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSX) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) TargetDescription(jdk.vm.ci.code.TargetDescription) JavaConstant(jdk.vm.ci.meta.JavaConstant) PlatformKind(jdk.vm.ci.meta.PlatformKind) ValueNode(org.graalvm.compiler.nodes.ValueNode) Value(jdk.vm.ci.meta.Value) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) Access(org.graalvm.compiler.nodes.memory.Access) ADD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD) SS(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SS) DWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.DWORD) GraalError(org.graalvm.compiler.debug.GraalError) ValueKind(jdk.vm.ci.meta.ValueKind) MatchRule(org.graalvm.compiler.core.match.MatchRule) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) MOVSXB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXB) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) SD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) AMD64RRMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp) AMD64(jdk.vm.ci.amd64.AMD64) AMD64MIOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp) ValueCompareAndSwapNode(org.graalvm.compiler.nodes.java.ValueCompareAndSwapNode) MOVSXD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXD) Condition(org.graalvm.compiler.core.common.calc.Condition) CPUFeature(jdk.vm.ci.amd64.AMD64.CPUFeature) LIRKind(org.graalvm.compiler.core.common.LIRKind) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) SSEOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp) OR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.OR) LIRValueUtil(org.graalvm.compiler.lir.LIRValueUtil) NodeMatchRules(org.graalvm.compiler.core.gen.NodeMatchRules) XOR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.XOR) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool) AND(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.AND) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) QWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.QWORD) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) Condition(org.graalvm.compiler.core.common.calc.Condition) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRKind(org.graalvm.compiler.core.common.LIRKind) LabelRef(org.graalvm.compiler.lir.LabelRef) MatchRule(org.graalvm.compiler.core.match.MatchRule)

Example 19 with IfNode

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));
        }
    }
}
Also used : IfNode(org.graalvm.compiler.nodes.IfNode)

Example 20 with IfNode

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;
}
Also used : IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

IfNode (org.graalvm.compiler.nodes.IfNode)27 ValueNode (org.graalvm.compiler.nodes.ValueNode)15 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)14 BeginNode (org.graalvm.compiler.nodes.BeginNode)10 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)10 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)7 Node (org.graalvm.compiler.graph.Node)6 EndNode (org.graalvm.compiler.nodes.EndNode)6 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)6 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)5 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)5 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 Value (jdk.vm.ci.meta.Value)4 Condition (org.graalvm.compiler.core.common.calc.Condition)4