Search in sources :

Example 1 with SizableInfo

use of com.oracle.svm.hosted.c.info.SizableInfo in project graal by oracle.

the class CInterfaceInvocationPlugin method replaceAccessor.

private boolean replaceAccessor(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo, int displacement) {
    StructuredGraph graph = b.getGraph();
    SizableInfo sizableInfo = (SizableInfo) accessorInfo.getParent();
    int elementSize = sizableInfo.getSizeInfo().getProperty();
    boolean isUnsigned = sizableInfo.isUnsigned();
    assert args.length == accessorInfo.parameterCount(true);
    ValueNode base = args[accessorInfo.baseParameterNumber(true)];
    switch(accessorInfo.getAccessorKind()) {
        case ADDRESS:
            {
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                b.addPush(pushKind(method), address);
                return true;
            }
        case GETTER:
            {
                JavaKind resultKind = wordTypes.asKind(b.getInvokeReturnType());
                JavaKind readKind = kindFromSize(elementSize, resultKind);
                if (readKind == JavaKind.Object) {
                    assert resultKind == JavaKind.Object;
                } else if (readKind.getBitCount() > resultKind.getBitCount() && !readKind.isNumericFloat() && resultKind != JavaKind.Boolean) {
                    readKind = resultKind;
                }
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
                Stamp stamp;
                if (readKind == JavaKind.Object) {
                    stamp = b.getInvokeReturnStamp(null).getTrustedStamp();
                } else if (readKind == JavaKind.Float || readKind == JavaKind.Double) {
                    stamp = StampFactory.forKind(readKind);
                } else {
                    stamp = StampFactory.forInteger(readKind.getBitCount());
                }
                ValueNode read = readOp(b, address, locationIdentity, stamp, accessorInfo);
                ValueNode adapted = adaptPrimitiveType(graph, read, readKind, resultKind == JavaKind.Boolean ? resultKind : resultKind.getStackKind(), isUnsigned);
                b.push(pushKind(method), adapted);
                return true;
            }
        case SETTER:
            {
                ValueNode value = args[accessorInfo.valueParameterNumber(true)];
                JavaKind valueKind = value.getStackKind();
                JavaKind writeKind = kindFromSize(elementSize, valueKind);
                ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
                LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
                ValueNode adaptedValue = adaptPrimitiveType(graph, value, valueKind, writeKind, isUnsigned);
                writeOp(b, address, locationIdentity, adaptedValue, accessorInfo);
                return true;
            }
        default:
            throw shouldNotReachHere();
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) ValueNode(org.graalvm.compiler.nodes.ValueNode) LocationIdentity(org.graalvm.word.LocationIdentity) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 2 with SizableInfo

use of com.oracle.svm.hosted.c.info.SizableInfo in project graal by oracle.

the class SizeAndSignednessVerifier method visitAccessorInfo.

@Override
protected void visitAccessorInfo(AccessorInfo accessorInfo) {
    ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
    ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
    if (accessorInfo.getParent() instanceof StructBitfieldInfo) {
        StructBitfieldInfo bitfieldInfo = (StructBitfieldInfo) accessorInfo.getParent();
        switch(accessorInfo.getAccessorKind()) {
            case GETTER:
            case SETTER:
                checkSignedness(bitfieldInfo.isUnsigned(), returnType, method);
                break;
            default:
                assert false;
        }
    } else {
        SizableInfo sizableInfo = (SizableInfo) accessorInfo.getParent();
        switch(accessorInfo.getAccessorKind()) {
            case ADDRESS:
                assert nativeLibs.isPointerBase(returnType);
                break;
            case OFFSET:
                assert returnType.getJavaKind().isNumericInteger() || nativeLibs.isUnsigned(returnType);
                break;
            case GETTER:
                checkSizeAndSignedness(sizableInfo, returnType, method, true);
                break;
            case SETTER:
                assert returnType.getJavaKind() == JavaKind.Void;
                ResolvedJavaType valueType = (ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.valueParameterNumber(false), method.getDeclaringClass());
                checkSizeAndSignedness(sizableInfo, valueType, method, false);
                break;
        }
    }
}
Also used : SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

SizableInfo (com.oracle.svm.hosted.c.info.SizableInfo)2 CInterfaceLocationIdentity (com.oracle.svm.core.c.struct.CInterfaceLocationIdentity)1 StructBitfieldInfo (com.oracle.svm.hosted.c.info.StructBitfieldInfo)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 LocationIdentity (org.graalvm.word.LocationIdentity)1