Search in sources :

Example 16 with PrimitiveConstant

use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.

the class IfNode method checkForUnsignedCompare.

/**
 * Recognize a couple patterns that can be merged into an unsigned compare.
 *
 * @param tool
 * @return true if a replacement was done.
 */
private boolean checkForUnsignedCompare(SimplifierTool tool) {
    assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages();
    if (condition() instanceof IntegerLessThanNode) {
        NodeView view = NodeView.from(tool);
        IntegerLessThanNode lessThan = (IntegerLessThanNode) condition();
        Constant y = lessThan.getY().stamp(view).asConstant();
        if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) {
            IfNode ifNode2 = (IfNode) falseSuccessor().next();
            if (ifNode2.condition() instanceof IntegerLessThanNode) {
                IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
                AbstractBeginNode falseSucc = ifNode2.falseSuccessor();
                AbstractBeginNode trueSucc = ifNode2.trueSuccessor();
                IntegerBelowNode below = null;
                /*
                     * Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
                     * <positive> into an unsigned compare.
                     */
                if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp(view) instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp(view)).isPositive() && sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
                    below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY()));
                    // swap direction
                    AbstractBeginNode tmp = falseSucc;
                    falseSucc = trueSucc;
                    trueSucc = tmp;
                } else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
                    /*
                         * Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
                         * !(<positive> > x), into x <| positive + 1. This can only be done for
                         * constants since there isn't a IntegerBelowEqualThanNode but that doesn't
                         * appear to be interesting.
                         */
                    JavaConstant positive = lessThan2.getX().asJavaConstant();
                    if (positive != null && positive.asLong() > 0 && positive.asLong() < positive.getJavaKind().getMaxValue()) {
                        ConstantNode newLimit = ConstantNode.forIntegerStamp(lessThan2.getX().stamp(view), positive.asLong() + 1, graph());
                        below = graph().unique(new IntegerBelowNode(lessThan.getX(), newLimit));
                    }
                }
                if (below != null) {
                    ifNode2.setTrueSuccessor(null);
                    ifNode2.setFalseSuccessor(null);
                    IfNode newIfNode = graph().add(new IfNode(below, falseSucc, trueSucc, 1 - trueSuccessorProbability));
                    // Remove the < 0 test.
                    tool.deleteBranch(trueSuccessor);
                    graph().removeSplit(this, falseSuccessor);
                    // Replace the second test with the new one.
                    ifNode2.predecessor().replaceFirstSuccessor(ifNode2, newIfNode);
                    ifNode2.safeDelete();
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 17 with PrimitiveConstant

use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.

the class VerifyDebugUsage method verifyDumpLevelParameter.

/**
 * The {@code level} arg for the {@code Debug.dump(...)} methods must be a reference to one of
 * the {@code Debug.*_LEVEL} constants.
 */
protected Integer verifyDumpLevelParameter(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, ResolvedJavaMethod verifiedCallee, ValueNode arg) throws org.graalvm.compiler.phases.VerifyPhase.VerificationError {
    // The 'level' arg for the Debug.dump(...) methods must be a reference to one of
    // the Debug.*_LEVEL constants.
    Constant c = arg.asConstant();
    if (c != null) {
        Integer dumpLevel = ((PrimitiveConstant) c).asInt();
        if (!DebugLevels.contains(dumpLevel)) {
            StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci());
            throw new VerificationError("In %s: parameter 0 of call to %s does not match a Debug.*_LEVEL constant: %s.%n", e, verifiedCallee.format("%H.%n(%p)"), dumpLevel);
        }
        return dumpLevel;
    }
    StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci());
    throw new VerificationError("In %s: parameter 0 of call to %s must be a constant, not %s.%n", e, verifiedCallee.format("%H.%n(%p)"), arg);
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant)

Aggregations

PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)17 Constant (jdk.vm.ci.meta.Constant)8 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 SignedWord (org.graalvm.word.SignedWord)2 AnalysisObject (com.oracle.graal.pointsto.flow.context.object.AnalysisObject)1 ConstantContextSensitiveObject (com.oracle.graal.pointsto.flow.context.object.ConstantContextSensitiveObject)1 RegisterValue (jdk.vm.ci.code.RegisterValue)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 MemoryAccessProvider (jdk.vm.ci.meta.MemoryAccessProvider)1 Value (jdk.vm.ci.meta.Value)1 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 GraalHotSpotVMConfig (org.graalvm.compiler.hotspot.GraalHotSpotVMConfig)1 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)1 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)1 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)1