Search in sources :

Example 1 with StructMember

use of com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.StructMember in project graal by oracle.

the class NativeMemSetNode method getAccessLength.

static long getAccessLength(LLVMManagedPointer pointer, long length, NativeTypeLibrary nativeTypes) {
    Object object = pointer.getObject();
    Object type = nativeTypes.getNativeType(object);
    if (type instanceof LLVMInteropType.Array) {
        long elementSize = ((LLVMInteropType.Array) type).elementSize;
        if (length % elementSize == 0) {
            return elementSize;
        }
    }
    if (type instanceof LLVMInteropType.Struct) {
        StructMember member = findMember((Struct) type, pointer.getOffset());
        /*
             * That's a bit of a guess: We assume that this tries to set 'n' members of the same
             * size. So, we just take the size of the first member as the access length. If that
             * isn't true, we will fail afterwards when doing actual access.
             */
        if (member != null && member.type instanceof LLVMInteropType.Value && length % member.type.getSize() == 0) {
            return member.type.getSize();
        }
    }
    /*
         * Fallback to byte-wise copy if either the type is unknown, not an array, or the length is
         * not a multiple of the array element size.
         */
    return 1;
}
Also used : StructMember(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.StructMember) Struct(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct)

Aggregations

Struct (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct)1 StructMember (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.StructMember)1