Search in sources :

Example 21 with Constant

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

the class PrimitiveStampBoundaryTest method checkUnaryOperation.

private static void checkUnaryOperation(ArithmeticOpTable.UnaryOp<?> op, Stamp result, Stamp v1stamp) {
    Stamp folded = op.foldStamp(v1stamp);
    Constant v1constant = v1stamp.asConstant();
    if (v1constant != null) {
        Constant constant = op.foldConstant(v1constant);
        if (constant != null) {
            Constant constant2 = folded.asConstant();
            if (constant2 == null && v1stamp instanceof FloatStamp) {
                JavaConstant c = (JavaConstant) constant;
                assertTrue((c.getJavaKind() == JavaKind.Double && Double.isNaN(c.asDouble())) || (c.getJavaKind() == JavaKind.Float && Float.isNaN(c.asFloat())));
            } else {
                assertTrue(constant2 != null, "should constant fold %s %s %s", op, v1stamp, folded);
                assertTrue(constant.equals(constant2), "should produce same constant %s %s %s %s", op, v1stamp, constant, constant2);
            }
        }
    } else {
        assertTrue(v1stamp.isEmpty() || v1stamp instanceof FloatStamp);
    }
    assertTrue(result.meet(folded).equals(result), "result out of range %s %s %s %s %s", op, v1stamp, folded, result, result.meet(folded));
}
Also used : PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 22 with Constant

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

the class MoveResolver method addMapping.

public void addMapping(Interval fromInterval, Interval toInterval) {
    DebugContext debug = allocator.getDebug();
    if (isIllegal(toInterval.location()) && toInterval.canMaterialize()) {
        if (debug.isLogEnabled()) {
            debug.log("no store to rematerializable interval %s needed", toInterval);
        }
        return;
    }
    if (isIllegal(fromInterval.location()) && fromInterval.canMaterialize()) {
        // Instead of a reload, re-materialize the value
        Constant rematValue = fromInterval.getMaterializedValue();
        addMapping(rematValue, toInterval);
        return;
    }
    if (debug.isLogEnabled()) {
        debug.log("add move mapping from %s to %s", fromInterval, toInterval);
    }
    assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
    assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", fromInterval.kind(), toInterval.kind(), fromInterval, toInterval);
    mappingFrom.add(fromInterval);
    mappingFromOpr.add(null);
    mappingTo.add(toInterval);
}
Also used : Constant(jdk.vm.ci.meta.Constant) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 23 with Constant

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

the class MulNode method canonical.

private static ValueNode canonical(MulNode self, BinaryOp<Mul> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
            long i = ((PrimitiveConstant) c).asLong();
            ValueNode result = canonical(stamp, forX, i, view);
            if (result != null) {
                return result;
            }
        }
        if (op.isAssociative()) {
            // canonicalize expressions like "(a * 1) * 2"
            return reassociate(self != null ? self : (MulNode) new MulNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
        }
    }
    return self != null ? self : new MulNode(forX, forY).maybeCommuteInputs();
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 24 with Constant

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

the class FloatStamp method maybeFoldConstant.

private static Stamp maybeFoldConstant(BinaryOp<?> op, FloatStamp stamp1, FloatStamp stamp2) {
    if (stamp1.isConstant() && stamp2.isConstant()) {
        JavaConstant constant1 = stamp1.asConstant();
        JavaConstant constant2 = stamp2.asConstant();
        Constant folded = op.foldConstant(constant1, constant2);
        if (folded != null) {
            FloatStamp stamp = stampForConstant(folded);
            if (stamp != null && stamp.isConstant()) {
                assert stamp.asConstant().equals(folded);
                return stamp;
            }
        }
    }
    return null;
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) SerializableConstant(jdk.vm.ci.meta.SerializableConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 25 with Constant

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

the class FloatStamp method maybeFoldConstant.

private static Stamp maybeFoldConstant(UnaryOp<?> op, FloatStamp stamp) {
    if (stamp.isConstant()) {
        JavaConstant constant = stamp.asConstant();
        Constant folded = op.foldConstant(constant);
        if (folded != null) {
            return FloatStamp.stampForConstant(folded);
        }
    }
    return null;
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) SerializableConstant(jdk.vm.ci.meta.SerializableConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

Constant (jdk.vm.ci.meta.Constant)31 JavaConstant (jdk.vm.ci.meta.JavaConstant)15 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)11 ValueNode (org.graalvm.compiler.nodes.ValueNode)9 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)5 Stamp (org.graalvm.compiler.core.common.type.Stamp)5 ArrayList (java.util.ArrayList)4 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)4 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)3 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)3 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)3 RegisterValue (jdk.vm.ci.code.RegisterValue)2 HotSpotCompressedNullConstant (jdk.vm.ci.hotspot.HotSpotCompressedNullConstant)2 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 SerializableConstant (jdk.vm.ci.meta.SerializableConstant)2 VMConstant (jdk.vm.ci.meta.VMConstant)2 Value (jdk.vm.ci.meta.Value)2 OperandSize (org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)2