Search in sources :

Example 1 with PrimitiveKind

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind in project sulong by graalvm.

the class Type method getFrameSlotKind.

public static FrameSlotKind getFrameSlotKind(Type type) {
    if (type instanceof PrimitiveType) {
        PrimitiveType primitive = (PrimitiveType) type;
        PrimitiveKind kind = primitive.getPrimitiveKind();
        switch(kind) {
            case FLOAT:
                return FrameSlotKind.Float;
            case DOUBLE:
                return FrameSlotKind.Double;
            case I1:
                return FrameSlotKind.Boolean;
            case I16:
            case I32:
                return FrameSlotKind.Int;
            case I64:
                return FrameSlotKind.Long;
            case I8:
                return FrameSlotKind.Byte;
            default:
                return FrameSlotKind.Object;
        }
    } else if (type instanceof VariableBitWidthType) {
        switch(type.getBitSize()) {
            case 1:
                return FrameSlotKind.Boolean;
            case 8:
                return FrameSlotKind.Byte;
            case 16:
            case 32:
                return FrameSlotKind.Int;
            case 64:
                return FrameSlotKind.Long;
            default:
                return FrameSlotKind.Object;
        }
    }
    return FrameSlotKind.Object;
}
Also used : PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)

Example 2 with PrimitiveKind

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind in project sulong by graalvm.

the class Type method isFloatingpointType.

public static boolean isFloatingpointType(Type type) {
    if (type instanceof PrimitiveType) {
        PrimitiveType primitive = (PrimitiveType) type;
        PrimitiveKind kind = primitive.getPrimitiveKind();
        return kind == PrimitiveKind.F128 || kind == PrimitiveKind.FLOAT || kind == PrimitiveKind.HALF || kind == PrimitiveKind.PPC_FP128 || kind == PrimitiveKind.X86_FP80 || kind == PrimitiveKind.DOUBLE;
    }
    return false;
}
Also used : PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)

Example 3 with PrimitiveKind

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind in project sulong by graalvm.

the class AsmFactory method addFrameSlot.

void addFrameSlot(String reg, Type type) {
    if (!registers.contains(reg)) {
        registers.add(reg);
        FrameSlotKind kind;
        if (type instanceof PrimitiveType) {
            PrimitiveKind primitiveKind = ((PrimitiveType) type).getPrimitiveKind();
            switch(primitiveKind) {
                case I8:
                    kind = FrameSlotKind.Byte;
                    break;
                case I32:
                    kind = FrameSlotKind.Int;
                    break;
                case I64:
                    kind = FrameSlotKind.Long;
                    break;
                default:
                    kind = FrameSlotKind.Illegal;
                    break;
            }
        } else if (type instanceof PointerType) {
            kind = FrameSlotKind.Object;
        } else {
            kind = FrameSlotKind.Illegal;
        }
        this.frameDescriptor.addFrameSlot(reg, type, kind);
    }
}
Also used : FrameSlotKind(com.oracle.truffle.api.frame.FrameSlotKind) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)

Example 4 with PrimitiveKind

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind in project sulong by graalvm.

the class AsmFactory method getArguments.

private void getArguments() {
    LLVMStoreNode[] writeNodes = null;
    LLVMExpressionNode[] valueNodes = null;
    if (retType instanceof StructureType) {
        writeNodes = new LLVMStoreNode[retTypes.length];
        valueNodes = new LLVMExpressionNode[retTypes.length];
    }
    Set<String> todoRegisters = new HashSet<>(registers);
    for (Argument arg : argInfo) {
        // output register
        if (arg.isOutput()) {
            FrameSlot slot = null;
            if (arg.isRegister()) {
                slot = getRegisterSlot(arg.getRegister());
                LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(slot);
                if (retType instanceof StructureType) {
                    assert retTypes[arg.getOutIndex()] == arg.getType();
                    if (arg.getType() instanceof PointerType) {
                        valueNodes[arg.getOutIndex()] = LLVMToAddressNodeGen.create(register);
                        writeNodes[arg.getOutIndex()] = LLVMAddressStoreNodeGen.create(null, null);
                    } else {
                        PrimitiveKind primitiveKind = getPrimitiveKind(arg);
                        switch(primitiveKind) {
                            case I8:
                                valueNodes[arg.getOutIndex()] = LLVMToI8NoZeroExtNodeGen.create(register);
                                writeNodes[arg.getOutIndex()] = LLVMI8StoreNodeGen.create(null, null);
                                break;
                            case I16:
                                valueNodes[arg.getOutIndex()] = LLVMToI16NoZeroExtNodeGen.create(register);
                                writeNodes[arg.getOutIndex()] = LLVMI16StoreNodeGen.create(null, null);
                                break;
                            case I32:
                                valueNodes[arg.getOutIndex()] = LLVMToI32NoZeroExtNodeGen.create(register);
                                writeNodes[arg.getOutIndex()] = LLVMI32StoreNodeGen.create(null, null);
                                break;
                            case I64:
                                valueNodes[arg.getOutIndex()] = register;
                                writeNodes[arg.getOutIndex()] = LLVMI64StoreNodeGen.create(null, null);
                                break;
                            default:
                                throw new AsmParseException("invalid operand size: " + arg.getType());
                        }
                    }
                } else {
                    result = castResult(register);
                }
            } else {
                assert arg.isMemory();
                slot = getArgumentSlot(arg.getIndex(), argTypes[arg.getOutIndex()]);
                LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getOutIndex());
                arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, sourceLocation));
            }
        }
        // input register
        if (arg.isInput()) {
            FrameSlot slot = null;
            if (arg.isRegister()) {
                String reg = arg.isAnonymous() ? arg.getRegister() : AsmRegisterOperand.getBaseRegister(arg.getRegister());
                slot = getRegisterSlot(reg);
                todoRegisters.remove(reg);
                LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getInIndex());
                if (argTypes[arg.getInIndex()] instanceof PointerType) {
                    arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, null));
                } else {
                    LLVMExpressionNode node = LLVMToI64NoZeroExtNodeGen.create(argnode);
                    arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
                }
            }
            slot = getArgumentSlot(arg.getIndex(), argTypes[arg.getInIndex()]);
            LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getInIndex());
            if (arg.getType() instanceof PrimitiveType) {
                LLVMExpressionNode node = LLVMToI64NoZeroExtNodeGen.create(argnode);
                arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
            } else if (arg.getType() instanceof PointerType) {
                arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, null));
            } else {
                throw new AsmParseException("invalid operand size: " + arg.getType());
            }
        }
    }
    if (retType instanceof StructureType) {
        LLVMExpressionNode addrArg = LLVMArgNodeGen.create(1);
        FrameSlot slot = frameDescriptor.addFrameSlot("returnValue", null, FrameSlotKind.Object);
        LLVMWriteAddressNode writeAddr = LLVMWriteAddressNodeGen.create(addrArg, slot, null);
        statements.add(writeAddr);
        LLVMExpressionNode addr = LLVMAddressReadNodeGen.create(slot);
        this.result = StructLiteralNodeGen.create(retOffsets, writeNodes, valueNodes, addr);
    }
    // rsp is initialized to stack pointer; ignore it here
    todoRegisters.remove("rsp");
    // initialize registers
    for (String register : todoRegisters) {
        if (register.startsWith("$")) {
            continue;
        }
        LLVMExpressionNode node = LLVMAMD64I64NodeGen.create(0);
        FrameSlot slot = getRegisterSlot(register);
        arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
    }
    // initialize flags
    LLVMExpressionNode zero = LLVMAMD64I1NodeGen.create(false);
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.CF), sourceLocation));
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.PF), sourceLocation));
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.AF), sourceLocation));
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.ZF), sourceLocation));
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.SF), sourceLocation));
    arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.OF), sourceLocation));
    // copy stack pointer
    LLVMExpressionNode stackPointer = LLVMArgNodeGen.create(0);
    FrameSlot stackSlot = frameDescriptor.addFrameSlot(LLVMStack.FRAME_ID);
    stackSlot.setKind(FrameSlotKind.Object);
    arguments.add(LLVMWriteAddressNodeGen.create(stackPointer, frameDescriptor.findFrameSlot(LLVMStack.FRAME_ID), sourceLocation));
    arguments.add(LLVMWriteAddressNodeGen.create(stackPointer, getRegisterSlot("rsp"), null));
    assert retType instanceof VoidType || retType != null;
}
Also used : VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind) LLVMWriteAddressNode(com.oracle.truffle.llvm.nodes.vars.LLVMWriteNode.LLVMWriteAddressNode) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMStoreNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStoreNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) HashSet(java.util.HashSet)

Example 5 with PrimitiveKind

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind in project sulong by graalvm.

the class Type method isIntegerType.

public static boolean isIntegerType(Type type) {
    if (type instanceof PrimitiveType) {
        PrimitiveType primitive = (PrimitiveType) type;
        PrimitiveKind kind = primitive.getPrimitiveKind();
        return kind == PrimitiveKind.I1 || kind == PrimitiveKind.I8 || kind == PrimitiveKind.I16 || kind == PrimitiveKind.I32 || kind == PrimitiveKind.I64;
    }
    return type instanceof VariableBitWidthType;
}
Also used : PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)

Aggregations

PrimitiveKind (com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)5 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)2 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 FrameSlotKind (com.oracle.truffle.api.frame.FrameSlotKind)1 LLVMWriteAddressNode (com.oracle.truffle.llvm.nodes.vars.LLVMWriteNode.LLVMWriteAddressNode)1 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)1 LLVMStoreNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMStoreNode)1 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)1 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)1 HashSet (java.util.HashSet)1