Search in sources :

Example 1 with PrimitiveConstant

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

the class AMD64HotSpotLIRGenerator method emitCCall.

@Override
public void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args, int numberOfFloatingPointArguments) {
    Value[] argLocations = new Value[args.length];
    getResult().getFrameMapBuilder().callsMethod(nativeCallingConvention);
    // TODO(mg): in case a native function uses floating point varargs, the ABI requires that
    // RAX contains the length of the varargs
    PrimitiveConstant intConst = JavaConstant.forInt(numberOfFloatingPointArguments);
    AllocatableValue numberOfFloatingPointArgumentsRegister = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD));
    emitMoveConstant(numberOfFloatingPointArgumentsRegister, intConst);
    for (int i = 0; i < args.length; i++) {
        Value arg = args[i];
        AllocatableValue loc = nativeCallingConvention.getArgument(i);
        emitMove(loc, arg);
        argLocations[i] = loc;
    }
    Value ptr = emitLoadConstant(LIRKind.value(AMD64Kind.QWORD), JavaConstant.forLong(address));
    append(new AMD64CCall(nativeCallingConvention.getReturn(), ptr, numberOfFloatingPointArgumentsRegister, argLocations));
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) RegisterValue(jdk.vm.ci.code.RegisterValue) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) AMD64CCall(org.graalvm.compiler.lir.amd64.AMD64CCall) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 2 with PrimitiveConstant

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

the class SubstrateMemoryAccessProviderImpl method readPrimitiveConstant.

@Override
public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, long displacement, int bits) {
    SignedWord offset = WordFactory.signed(displacement);
    long rawValue;
    if (baseConstant instanceof SubstrateObjectConstant) {
        Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
        assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
        switch(bits) {
            case Byte.SIZE:
                rawValue = BarrieredAccess.readByte(baseObject, offset);
                break;
            case Short.SIZE:
                rawValue = BarrieredAccess.readShort(baseObject, offset);
                break;
            case Integer.SIZE:
                rawValue = BarrieredAccess.readInt(baseObject, offset);
                break;
            case Long.SIZE:
                rawValue = BarrieredAccess.readLong(baseObject, offset);
                break;
            default:
                throw shouldNotReachHere();
        }
    } else if (baseConstant instanceof PrimitiveConstant) {
        PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
        if (!prim.getJavaKind().isNumericInteger()) {
            return null;
        }
        Pointer basePointer = WordFactory.unsigned(prim.asLong());
        if (basePointer.equal(0)) {
            return null;
        }
        switch(bits) {
            case Byte.SIZE:
                rawValue = basePointer.readByte(offset);
                break;
            case Short.SIZE:
                rawValue = basePointer.readShort(offset);
                break;
            case Integer.SIZE:
                rawValue = basePointer.readInt(offset);
                break;
            case Long.SIZE:
                rawValue = basePointer.readLong(offset);
                break;
            default:
                throw shouldNotReachHere();
        }
    } else {
        return null;
    }
    return toConstant(kind, rawValue);
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) Pointer(org.graalvm.word.Pointer) SignedWord(org.graalvm.word.SignedWord)

Example 3 with PrimitiveConstant

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

the class AArch64LIRGenerator method isCompareConstant.

/**
 * Checks whether value can be used directly with a gpCompare instruction. This is <b>not</b>
 * the same as {@link AArch64ArithmeticLIRGenerator#isArithmeticConstant(JavaConstant)}, because
 * 0.0 is a valid compare constant for floats, while there are no arithmetic constants for
 * floats.
 *
 * @param value any type. Non null.
 * @return true if value can be used directly in comparison instruction, false otherwise.
 */
public boolean isCompareConstant(Value value) {
    if (isJavaConstant(value)) {
        JavaConstant constant = asJavaConstant(value);
        if (constant instanceof PrimitiveConstant) {
            final long longValue = constant.asLong();
            long maskedValue;
            switch(constant.getJavaKind()) {
                case Boolean:
                case Byte:
                    maskedValue = longValue & 0xFF;
                    break;
                case Char:
                case Short:
                    maskedValue = longValue & 0xFFFF;
                    break;
                case Int:
                    maskedValue = longValue & 0xFFFF_FFFF;
                    break;
                case Long:
                    maskedValue = longValue;
                    break;
                default:
                    throw GraalError.shouldNotReachHere();
            }
            return AArch64MacroAssembler.isArithmeticImmediate(maskedValue);
        } else {
            return constant.isDefaultForKind();
        }
    }
    return false;
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 4 with PrimitiveConstant

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

the class SubNode method canonical.

private static ValueNode canonical(SubNode subNode, BinaryOp<Sub> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    SubNode self = subNode;
    if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
        Constant zero = op.getZero(forX.stamp(view));
        if (zero != null) {
            return ConstantNode.forPrimitive(stamp, zero);
        }
    }
    boolean associative = op.isAssociative();
    if (associative) {
        if (forX instanceof AddNode) {
            AddNode x = (AddNode) forX;
            if (x.getY() == forY) {
                // (a + b) - b
                return x.getX();
            }
            if (x.getX() == forY) {
                // (a + b) - a
                return x.getY();
            }
        } else if (forX instanceof SubNode) {
            SubNode x = (SubNode) forX;
            if (x.getX() == forY) {
                // (a - b) - a
                return NegateNode.create(x.getY(), view);
            }
        }
        if (forY instanceof AddNode) {
            AddNode y = (AddNode) forY;
            if (y.getX() == forX) {
                // a - (a + b)
                return NegateNode.create(y.getY(), view);
            }
            if (y.getY() == forX) {
                // b - (a + b)
                return NegateNode.create(y.getX(), view);
            }
        } else if (forY instanceof SubNode) {
            SubNode y = (SubNode) forY;
            if (y.getX() == forX) {
                // a - (a - b)
                return y.getY();
            }
        }
    }
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (associative && self != null) {
            ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
            if (reassociated != self) {
                return reassociated;
            }
        }
        if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
            long i = ((PrimitiveConstant) c).asLong();
            if (i < 0 || ((IntegerStamp) StampFactory.forKind(forY.getStackKind())).contains(-i)) {
                // commutative, so prefer add when it fits.
                return BinaryArithmeticNode.add(forX, ConstantNode.forIntegerStamp(stamp, -i), view);
            }
        }
    } else if (forX.isConstant()) {
        Constant c = forX.asConstant();
        if (ArithmeticOpTable.forStamp(stamp).getAdd().isNeutral(c)) {
            /*
                 * Note that for floating point numbers, + and - have different neutral elements. We
                 * have to test for the neutral element of +, because we are doing this
                 * transformation: 0 - x == (-x) + 0 == -x.
                 */
            return NegateNode.create(forY, view);
        }
        if (associative && self != null) {
            return reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
        }
    }
    if (forY instanceof NegateNode) {
        return BinaryArithmeticNode.add(forX, ((NegateNode) forY).getValue(), view);
    }
    return self != null ? self : new SubNode(forX, forY);
}
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 5 with PrimitiveConstant

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

the class OrNode method canonical.

private static ValueNode canonical(OrNode self, BinaryOp<Or> 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 OrNode(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 ConstantNode.forIntegerStamp(stamp, mask);
            }
        }
        return reassociate(self != null ? self : (OrNode) new OrNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
    }
    if (forX instanceof NotNode && forY instanceof NotNode) {
        return new NotNode(AndNode.create(((NotNode) forX).getValue(), ((NotNode) forY).getValue(), view));
    }
    return self != null ? self : new OrNode(forX, forY).maybeCommuteInputs();
}
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