Search in sources :

Example 16 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class AsmFactory method getOperandStore.

private LLVMExpressionNode getOperandStore(Type type, AsmOperand operand, LLVMExpressionNode from) {
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
        int shift = op.getShift();
        LLVMExpressionNode out = null;
        assert (type instanceof PointerType && op.getType() == PrimitiveType.I64) || (op.getType() instanceof PointerType && type == PrimitiveType.I64) || (type == op.getType());
        switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
            case I8:
                out = LLVMI8ToR64NodeGen.create(shift, register, from);
                break;
            case I16:
                out = LLVMI16ToR64NodeGen.create(register, from);
                break;
            case I32:
                out = LLVMI32ToR64NodeGen.create(from);
                break;
            case I64:
                out = from;
                break;
            default:
                throw new AsmParseException("unsupported operand type: " + op.getType());
        }
        return LLVMWriteI64NodeGen.create(out, frame, null);
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        if (info.isMemory()) {
            LLVMExpressionNode address = info.getAddress();
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8StoreNodeGen.create(address, from);
                case I16:
                    return LLVMI16StoreNodeGen.create(address, from);
                case I32:
                    return LLVMI32StoreNodeGen.create(address, from);
                case I64:
                    return LLVMI64StoreNodeGen.create(address, from);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (info.isRegister()) {
            FrameSlot frame = getRegisterSlot(info.getRegister());
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            LLVMExpressionNode out = null;
            if (type instanceof PointerType || info.getType() instanceof PointerType) {
                return LLVMAMD64WriteAddressRegisterNodeGen.create(sourceLocation, from, frame);
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    out = LLVMI8ToR64NodeGen.create(0, register, from);
                    break;
                case I16:
                    out = LLVMI16ToR64NodeGen.create(register, from);
                    break;
                case I32:
                    out = LLVMI32ToR64NodeGen.create(from);
                    break;
                case I64:
                    out = from;
                    break;
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
            return LLVMWriteI64NodeGen.create(out, frame, null);
        } else {
            throw new AssertionError("this should not happen; " + info);
        }
    } else if (operand instanceof AsmMemoryOperand) {
        LLVMExpressionNode address = getOperandAddress(operand);
        switch(((PrimitiveType) type).getPrimitiveKind()) {
            case I8:
                return LLVMI8StoreNodeGen.create(null, address, from);
            case I16:
                return LLVMI16StoreNodeGen.create(null, address, from);
            case I32:
                return LLVMI32StoreNodeGen.create(null, address, from);
            case I64:
                return LLVMI64StoreNodeGen.create(null, address, from);
            default:
                throw new AsmParseException("unsupported operand type: " + type);
        }
    }
    throw new AsmParseException("unsupported operand type: " + operand);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 17 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class AsmFactory method getRegisterSlot.

private FrameSlot getRegisterSlot(String name) {
    if (name.startsWith(TEMP_REGISTER_PREFIX)) {
        addFrameSlot(name, PrimitiveType.I64);
        return frameDescriptor.findFrameSlot(name);
    }
    AsmRegisterOperand op = new AsmRegisterOperand(name);
    String baseRegister = op.getBaseRegister();
    addFrameSlot(baseRegister, PrimitiveType.I64);
    FrameSlot frame = frameDescriptor.findFrameSlot(baseRegister);
    return frame;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot)

Example 18 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class AsmFactory method getOperandLoad.

private LLVMExpressionNode getOperandLoad(Type typeHint, AsmOperand operand) {
    Type type = typeHint == null ? operand.getType() : typeHint;
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
        int shift = op.getShift();
        assert type instanceof PointerType || type == op.getType();
        if (type instanceof PointerType) {
            switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMAMD64ReadAddressNodeGen.create(frame);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
        switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
            case I8:
                return LLVMAMD64I64ToI8NodeGen.create(shift, register);
            case I16:
                return LLVMToI16NoZeroExtNodeGen.create(register);
            case I32:
                return LLVMToI32NoZeroExtNodeGen.create(register);
            case I64:
                return register;
            default:
                throw new AsmParseException("unsupported operand type: " + type);
        }
    } else if (operand instanceof AsmImmediateOperand) {
        AsmImmediateOperand op = (AsmImmediateOperand) operand;
        if (op.isLabel()) {
            throw new AsmParseException("labels not supported");
        } else {
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMAMD64I8NodeGen.create((byte) op.getValue());
                case I16:
                    return LLVMAMD64I16NodeGen.create((short) op.getValue());
                case I32:
                    return LLVMAMD64I32NodeGen.create((int) op.getValue());
                case I64:
                    return LLVMAMD64I64NodeGen.create(op.getValue());
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        FrameSlot frame = getArgumentSlot(op.getIndex(), type);
        if (info.isMemory()) {
            if (type instanceof PointerType) {
                return LLVMAddressDirectLoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I16:
                    return LLVMI16LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I32:
                    return LLVMI32LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I64:
                    return LLVMI64LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (info.isRegister()) {
            frame = getRegisterSlot(info.getRegister());
            if (type instanceof PointerType) {
                return LLVMAMD64ReadAddressNodeGen.create(frame);
            }
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMToI64NoZeroExtNodeGen.create(register);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else {
            // constraint "0"-"9"
            if (type instanceof PointerType) {
                return LLVMAMD64ReadAddressNodeGen.create(frame);
            }
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMToI64NoZeroExtNodeGen.create(register);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
    } else if (operand instanceof AsmMemoryOperand) {
        LLVMExpressionNode address = getOperandAddress(operand);
        LLVMExpressionNode addr = LLVMToAddressNodeGen.create(address);
        if (type instanceof PrimitiveType) {
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8LoadNodeGen.create(addr);
                case I16:
                    return LLVMI16LoadNodeGen.create(addr);
                case I32:
                    return LLVMI32LoadNodeGen.create(addr);
                case I64:
                    return LLVMI64LoadNodeGen.create(addr);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (type instanceof PointerType) {
            return LLVMAddressDirectLoadNodeGen.create(addr);
        } else {
            throw new AsmParseException("unsupported operand type: " + type);
        }
    }
    throw new AsmParseException("unsupported operand: " + operand);
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) Type(com.oracle.truffle.llvm.runtime.types.Type) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 19 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class LLVMSourceScope method getVariables.

@TruffleBoundary
protected Object getVariables(Frame frame) {
    final Map<String, LLVMDebugObject> vars = new HashMap<>();
    if (frame != null && !symbols.isEmpty()) {
        for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
            if (slot.getIdentifier() instanceof LLVMSourceSymbol && frame.getValue(slot) instanceof LLVMDebugValue) {
                final LLVMSourceSymbol symbol = (LLVMSourceSymbol) slot.getIdentifier();
                final LLVMDebugObject value = ((LLVMDebugValue) frame.getValue(slot)).getValue(symbol);
                if (symbols.contains(symbol)) {
                    vars.put(symbol.getName(), value);
                }
            }
        }
    }
    for (LLVMSourceSymbol symbol : symbols) {
        if (!vars.containsKey(symbol.getName())) {
            LLVMDebugValue dbgVal = context.getStatic(symbol);
            if (dbgVal == null) {
                final LLVMFrameValueAccess allocation = context.getFrameValue(symbol);
                if (allocation != null && frame != null) {
                    dbgVal = allocation.getValue(frame);
                }
            }
            if (dbgVal == null) {
                dbgVal = LLVMDebugValue.UNAVAILABLE;
            }
            vars.put(symbol.getName(), dbgVal.getValue(symbol));
        }
    }
    return new LLVMSourceScopeVariables(vars);
}
Also used : LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.LLVMDebugObject) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) HashMap(java.util.HashMap) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 20 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class LLVMContext method getGlobalFrameSlot.

public FrameSlot getGlobalFrameSlot(Object symbol, Type type) {
    FrameSlotKind kind;
    if (type instanceof PrimitiveType) {
        switch(((PrimitiveType) type).getPrimitiveKind()) {
            case DOUBLE:
                kind = FrameSlotKind.Double;
                break;
            case FLOAT:
                kind = FrameSlotKind.Float;
                break;
            case HALF:
            case I16:
            case I32:
                kind = FrameSlotKind.Int;
                break;
            case I1:
                kind = FrameSlotKind.Boolean;
                break;
            case I64:
                kind = FrameSlotKind.Long;
                break;
            case I8:
                kind = FrameSlotKind.Byte;
                break;
            default:
                kind = FrameSlotKind.Object;
                break;
        }
    } else {
        kind = FrameSlotKind.Object;
    }
    FrameSlot frameSlot = globalFrameDescriptor.findOrAddFrameSlot(symbol, type, kind);
    return frameSlot;
}
Also used : FrameSlotKind(com.oracle.truffle.api.frame.FrameSlotKind) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)47 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)12 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)10 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)7 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Type (com.oracle.truffle.llvm.runtime.types.Type)5 CallTarget (com.oracle.truffle.api.CallTarget)4 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)3 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Frame (com.oracle.truffle.api.frame.Frame)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2