Search in sources :

Example 21 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class LLVMVaListStorage method invokeMember.

@ExportMessage
public Object invokeMember(String member, Object[] arguments, @Cached.Shared("escapeNode") @Cached LLVMPointerDataEscapeNode pointerEscapeNode) throws ArityException, UnknownIdentifierException, UnsupportedTypeException {
    if (GET_MEMBER.equals(member)) {
        if (arguments.length == 2) {
            if (!(arguments[0] instanceof Integer)) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                throw UnsupportedTypeException.create(new Object[] { arguments[0] }, "Index argument must be an integer");
            }
            int i = (Integer) arguments[0];
            if (i >= realArguments.length - numberOfExplicitArguments) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                throw new ArrayIndexOutOfBoundsException(i);
            }
            Object arg = realArguments[numberOfExplicitArguments + i];
            if (!(arguments[1] instanceof LLVMInteropType.Structured)) {
                return arg;
            }
            LLVMInteropType.Structured type = (LLVMInteropType.Structured) arguments[1];
            if (!LLVMPointer.isInstance(arg)) {
                // arg's types
                return arg;
            }
            LLVMPointer ptrArg = LLVMPointer.cast(arg);
            return pointerEscapeNode.executeWithType(ptrArg, type);
        } else {
            throw ArityException.create(2, 2, arguments.length);
        }
    }
    throw UnknownIdentifierException.create(member);
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 22 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class LLDBMemoryValue method loadValue.

private Object loadValue(Type loadtype, int byteOffset) {
    final LLVMPointer offsetPointer = pointer.increment(byteOffset);
    CallTarget loadFunction = LLVMLanguage.getLLDBSupport().getLoadFunction(loadtype);
    return loadFunction.call(offsetPointer);
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) CallTarget(com.oracle.truffle.api.CallTarget)

Example 23 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class LLVMArrayLiteralNode method foreignWrite.

@Specialization
@ExplodeLoop
protected LLVMPointer foreignWrite(VirtualFrame frame, LLVMPointer addr) {
    LLVMPointer currentPtr = addr;
    for (int i = 0; i < values.length; i++) {
        write.executeWithTarget(currentPtr, values[i].executeGeneric(frame));
        currentPtr = currentPtr.increment(stride);
    }
    return addr;
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 24 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class LLVMX86_64VaListStorage method shift.

/**
 * This is the implementation of the {@code va_arg} instruction.
 */
@SuppressWarnings("static-method")
@ExportMessage
Object shift(Type type, @SuppressWarnings("unused") Frame frame, @CachedLibrary(limit = "1") LLVMManagedReadLibrary readLib, @CachedLibrary(limit = "1") LLVMManagedWriteLibrary writeLib, @Cached BranchProfile regAreaProfile, @Cached("createBinaryProfile()") ConditionProfile isNativizedProfile) {
    int regSaveOffs = 0;
    int regSaveStep = 0;
    int regSaveLimit = 0;
    boolean lookIntoRegSaveArea = true;
    VarArgArea varArgArea = getVarArgArea(type);
    switch(varArgArea) {
        case GP_AREA:
            regSaveOffs = X86_64BitVarArgs.GP_OFFSET;
            regSaveStep = X86_64BitVarArgs.GP_STEP;
            regSaveLimit = X86_64BitVarArgs.GP_LIMIT;
            break;
        case FP_AREA:
            regSaveOffs = X86_64BitVarArgs.FP_OFFSET;
            regSaveStep = X86_64BitVarArgs.FP_STEP;
            regSaveLimit = X86_64BitVarArgs.FP_LIMIT;
            break;
        case OVERFLOW_AREA:
            lookIntoRegSaveArea = false;
            break;
    }
    if (lookIntoRegSaveArea) {
        regAreaProfile.enter();
        int offs = readLib.readI32(this, regSaveOffs);
        if (offs < regSaveLimit) {
            writeLib.writeI32(this, regSaveOffs, offs + regSaveStep);
            long n = this.regSaveArea.offsetToIndex(offs);
            int i = (int) ((n << 32) >> 32);
            return this.regSaveArea.args[i];
        }
    }
    // overflow area
    if (isNativizedProfile.profile(isNativized())) {
        // Synchronize the managed current argument pointer from the native overflow area
        this.overflowArgArea.setOffset(getArgPtrFromNativePtr(this, readLib));
        Object currentArg = this.overflowArgArea.getCurrentArg();
        // Shift the managed current argument pointer
        this.overflowArgArea.shift(1);
        // Update the new native current argument pointer from the managed one
        long shiftOffs = this.overflowArgArea.getOffset();
        LLVMPointer shiftedOverflowAreaPtr = overflowArgAreaBaseNativePtr.increment(shiftOffs);
        writeLib.writePointer(this, X86_64BitVarArgs.OVERFLOW_ARG_AREA, shiftedOverflowAreaPtr);
        return currentArg;
    } else {
        Object currentArg = this.overflowArgArea.getCurrentArg();
        this.overflowArgArea.shift(1);
        return currentArg;
    }
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 25 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class LLVMComplex80BitFloatMul method doMul.

@Specialization
public Object doMul(VirtualFrame frame, @Cached("getSizeInBytes()") int sizeInBytes) {
    try {
        LLVM80BitFloat longDoubleA = (LLVM80BitFloat) aNode.executeGeneric(frame);
        LLVM80BitFloat longDoubleB = (LLVM80BitFloat) bNode.executeGeneric(frame);
        LLVM80BitFloat longDoubleC = (LLVM80BitFloat) cNode.executeGeneric(frame);
        LLVM80BitFloat longDoubleD = (LLVM80BitFloat) dNode.executeGeneric(frame);
        double a = longDoubleA.getDoubleValue();
        double b = longDoubleB.getDoubleValue();
        double c = longDoubleC.getDoubleValue();
        double d = longDoubleD.getDoubleValue();
        double ac = a * c;
        double bd = b * d;
        double ad = a * d;
        double bc = b * c;
        double zReal = ac - bd;
        double zImag = ad + bc;
        LLVMPointer allocatedMemory = alloc.executeLLVMPointer(frame);
        store.executeWithTarget(allocatedMemory, LLVM80BitFloat.fromDouble(zReal));
        store.executeWithTarget(allocatedMemory.increment(sizeInBytes), LLVM80BitFloat.fromDouble(zImag));
        return allocatedMemory;
    } catch (UnexpectedResultException | ClassCastException e) {
        throw CompilerDirectives.shouldNotReachHere(e);
    }
}
Also used : UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVM80BitFloat(com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)33 Specialization (com.oracle.truffle.api.dsl.Specialization)12 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)4 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 ExportMessage (com.oracle.truffle.api.library.ExportMessage)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)3 BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)3 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)3 LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)3 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)3 Assumption (com.oracle.truffle.api.Assumption)2 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 LLVMForeignGetSuperElemPtrNode (com.oracle.truffle.llvm.runtime.interop.export.LLVMForeignGetSuperElemPtrNode)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 LLVMManagedPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer)2