Search in sources :

Example 11 with LogicNode

use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.

the class NormalizeCompareNode method tryConstantFold.

protected static ValueNode tryConstantFold(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
    LogicNode result = CompareNode.tryConstantFold(CanonicalCondition.EQ, x, y, null, false);
    if (result instanceof LogicConstantNode) {
        LogicConstantNode logicConstantNode = (LogicConstantNode) result;
        LogicNode resultLT = CompareNode.tryConstantFold(CanonicalCondition.LT, x, y, constantReflection, isUnorderedLess);
        if (resultLT instanceof LogicConstantNode) {
            LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
            if (logicConstantNodeLT.getValue()) {
                return ConstantNode.forIntegerKind(kind, -1);
            } else if (logicConstantNode.getValue()) {
                return ConstantNode.forIntegerKind(kind, 0);
            } else {
                return ConstantNode.forIntegerKind(kind, 1);
            }
        }
    }
    return null;
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 12 with LogicNode

use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.

the class HashMapGetTest method hashMapTest.

@Test
public void hashMapTest() {
    HashMap<Integer, Integer> map = new HashMap<>();
    ResolvedJavaMethod get = getResolvedJavaMethod(HashMapGetTest.class, "mapGet");
    for (int i = 0; i < 5000; i++) {
        mapGet(map, i);
        map.put(i, i);
        mapGet(map, i);
    }
    test(get, null, map, new Integer(0));
    for (IfNode ifNode : lastCompiledGraph.getNodes(IfNode.TYPE)) {
        LogicNode condition = ifNode.condition();
        if (ifNode.getTrueSuccessorProbability() < 0.4 && condition instanceof ObjectEqualsNode) {
            assertTrue(ifNode.trueSuccessor().next() instanceof ReturnNode, "Expected return.", ifNode.trueSuccessor(), ifNode.trueSuccessor().next());
        }
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) HashMap(java.util.HashMap) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Example 13 with LogicNode

use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.

the class BytecodeParser method genIf.

protected void genIf(ValueNode x, Condition cond, ValueNode y) {
    assert x.getStackKind() == y.getStackKind();
    assert currentBlock.getSuccessorCount() == 2;
    BciBlock trueBlock = currentBlock.getSuccessor(0);
    BciBlock falseBlock = currentBlock.getSuccessor(1);
    if (trueBlock == falseBlock) {
        // The target block is the same independent of the condition.
        appendGoto(trueBlock);
        return;
    }
    ValueNode a = x;
    ValueNode b = y;
    BciBlock trueSuccessor = trueBlock;
    BciBlock falseSuccessor = falseBlock;
    CanonicalizedCondition canonicalizedCondition = cond.canonicalize();
    // Check whether the condition needs to mirror the operands.
    if (canonicalizedCondition.mustMirror()) {
        a = y;
        b = x;
    }
    if (canonicalizedCondition.mustNegate()) {
        trueSuccessor = falseBlock;
        falseSuccessor = trueBlock;
    }
    // Create the logic node for the condition.
    LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b);
    double probability = -1;
    if (condition instanceof IntegerEqualsNode) {
        probability = extractInjectedProbability((IntegerEqualsNode) condition);
    // the probability coming from here is about the actual condition
    }
    if (probability == -1) {
        probability = getProfileProbability(canonicalizedCondition.mustNegate());
    }
    probability = clampProbability(probability);
    genIf(condition, trueSuccessor, falseSuccessor, probability);
}
Also used : CanonicalizedCondition(org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 14 with LogicNode

use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.

the class BytecodeParser method emitCheckForInvokeSuperSpecial.

/**
 * Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method
 * declared in an interface (i.e., a default method) is assignable to the interface. If not,
 * then deoptimize so that the interpreter can throw an {@link IllegalAccessError}.
 *
 * This is a check not performed by the verifier and so must be performed at runtime.
 *
 * @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a
 *            method in a super class
 */
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
    ResolvedJavaType callingClass = method.getDeclaringClass();
    if (callingClass.getHostClass() != null) {
        callingClass = callingClass.getHostClass();
    }
    if (callingClass.isInterface()) {
        ValueNode receiver = args[0];
        TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass);
        LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null));
        FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false));
        args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard));
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 15 with LogicNode

use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.

the class LoopTransformations method updateMainLoopLimit.

private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
    // Update the main loops limit test to be different than the post loop
    StructuredGraph graph = preLimit.graph();
    IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
    LogicNode ifTest = mainLimit.condition();
    CompareNode compareNode = (CompareNode) ifTest;
    ValueNode prePhi = preIv.valueNode();
    ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
    ValueNode preStride = preIv.strideNode();
    ValueNode mainStride;
    if (preStride instanceof ConstantNode) {
        mainStride = preStride;
    } else {
        mainStride = mainLoop.getDuplicatedNode(preStride);
    }
    // Fetch the bounds to pose lowering the range by one
    ValueNode ub = null;
    if (compareNode.getX() == mainPhi) {
        ub = compareNode.getY();
    } else if (compareNode.getY() == mainPhi) {
        ub = compareNode.getX();
    } else {
        throw GraalError.shouldNotReachHere();
    }
    // Preloop always performs at least one iteration, so remove that from the main loop.
    ValueNode newLimit = sub(graph, ub, mainStride);
    // Re-wire the condition with the new limit
    compareNode.replaceFirstInput(ub, newLimit);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Aggregations

LogicNode (org.graalvm.compiler.nodes.LogicNode)48 ValueNode (org.graalvm.compiler.nodes.ValueNode)37 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)26 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)11 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 Stamp (org.graalvm.compiler.core.common.type.Stamp)9 IfNode (org.graalvm.compiler.nodes.IfNode)9 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)8 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)7 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)6 JavaKind (jdk.vm.ci.meta.JavaKind)5 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)5 Node (org.graalvm.compiler.graph.Node)5