Search in sources :

Example 6 with PrimitiveConstant

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

the class AndNode method canonical.

private static ValueNode canonical(AndNode self, BinaryOp<And> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
        return forX;
    }
    if (forX.isConstant() && !forY.isConstant()) {
        return new AndNode(forY, forX);
    }
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
            long rawY = ((PrimitiveConstant) c).asLong();
            long mask = CodeUtil.mask(PrimitiveStamp.getBits(stamp));
            if ((rawY & mask) == 0) {
                return ConstantNode.forIntegerStamp(stamp, 0);
            }
            if (forX instanceof SignExtendNode) {
                SignExtendNode ext = (SignExtendNode) forX;
                if (rawY == ((1L << ext.getInputBits()) - 1)) {
                    return new ZeroExtendNode(ext.getValue(), ext.getResultBits());
                }
            }
            IntegerStamp xStamp = (IntegerStamp) forX.stamp(view);
            if (((xStamp.upMask() | xStamp.downMask()) & ~rawY) == 0) {
                // No bits are set which are outside the mask, so the mask will have no effect.
                return forX;
            }
        }
        return reassociate(self != null ? self : (AndNode) new AndNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
    }
    if (forX instanceof NotNode && forY instanceof NotNode) {
        return new NotNode(OrNode.create(((NotNode) forX).getValue(), ((NotNode) forY).getValue(), view));
    }
    return self != null ? self : new AndNode(forX, forY).maybeCommuteInputs();
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 7 with PrimitiveConstant

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

the class XorNode method canonical.

private static ValueNode canonical(XorNode self, BinaryOp<Xor> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
        return ConstantNode.forPrimitive(stamp, op.getZero(forX.stamp(view)));
    }
    if (forX.isConstant() && !forY.isConstant()) {
        return new XorNode(forY, forX);
    }
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
            long rawY = ((PrimitiveConstant) c).asLong();
            long mask = CodeUtil.mask(PrimitiveStamp.getBits(stamp));
            if ((rawY & mask) == mask) {
                return new NotNode(forX);
            }
        }
        return reassociate(self != null ? self : (XorNode) new XorNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
    }
    return self != null ? self : new XorNode(forX, forY).maybeCommuteInputs();
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant)

Example 8 with PrimitiveConstant

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

the class FloatStamp method stampForConstant.

private static FloatStamp stampForConstant(Constant constant) {
    FloatStamp result;
    PrimitiveConstant value = (PrimitiveConstant) constant;
    switch(value.getJavaKind()) {
        case Float:
            if (Float.isNaN(value.asFloat())) {
                result = new FloatStamp(32, Double.NaN, Double.NaN, false);
            } else {
                result = new FloatStamp(32, value.asFloat(), value.asFloat(), !Float.isNaN(value.asFloat()));
            }
            break;
        case Double:
            if (Double.isNaN(value.asDouble())) {
                result = new FloatStamp(64, Double.NaN, Double.NaN, false);
            } else {
                result = new FloatStamp(64, value.asDouble(), value.asDouble(), !Double.isNaN(value.asDouble()));
            }
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    if (result.isConstant()) {
        return result;
    }
    return null;
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant)

Example 9 with PrimitiveConstant

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

the class ConstantNode method forPrimitive.

/**
 * Returns a node for a primitive of a given type.
 */
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
    if (stamp instanceof IntegerStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
        IntegerStamp istamp = (IntegerStamp) stamp;
        return forIntegerBits(istamp.getBits(), primitive);
    } else if (stamp instanceof FloatStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
        return forConstant(primitive, null);
    } else {
        assert !(stamp instanceof AbstractObjectStamp);
        return new ConstantNode(constant, stamp.constant(constant, null));
    }
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 10 with PrimitiveConstant

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

the class UnsafeAutomaticSubstitutionProcessor method subNodeComputesLog2.

/**
 * Check if the SubNode computes log2 of one of it's operands. The order of operands is not
 * assumed; both permutations are checked.
 */
private static boolean subNodeComputesLog2(SubNode subNode, Invoke numberOfLeadingZerosInvokeNode) {
    ValueNode xValueNode = subNode.getX();
    ValueNode yValueNode = subNode.getY();
    if (xValueNode.isJavaConstant() && xValueNode.asJavaConstant().getJavaKind() == JavaKind.Int) {
        PrimitiveConstant xValueConstant = (PrimitiveConstant) xValueNode.asJavaConstant();
        if (xValueConstant.asInt() == 31) {
            assert yValueNode.equals(numberOfLeadingZerosInvokeNode);
            return true;
        }
    }
    if (yValueNode.isJavaConstant() && yValueNode.asJavaConstant().getJavaKind() == JavaKind.Int) {
        PrimitiveConstant yValueConstant = (PrimitiveConstant) yValueNode.asJavaConstant();
        if (yValueConstant.asInt() == 31) {
            assert xValueNode.equals(numberOfLeadingZerosInvokeNode);
            return true;
        }
    }
    return false;
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode)

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