Search in sources :

Example 11 with PrimitiveType

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

the class AsmFactory method getRegisterTarget.

private LLVMAMD64Target getRegisterTarget(Type type, String name) {
    AsmRegisterOperand op = new AsmRegisterOperand(name);
    FrameSlot frame = getRegisterSlot(name);
    switch(((PrimitiveType) type).getPrimitiveKind()) {
        case I8:
            return new LLVMAMD64Target(frame, op.getShift());
        case I16:
        case I32:
        case I64:
            return new LLVMAMD64Target(frame);
        default:
            throw new AsmParseException("unsupported operand type");
    }
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMAMD64Target(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64Target)

Example 12 with PrimitiveType

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

the class AsmFactory method getOperandAddress.

private LLVMExpressionNode getOperandAddress(Type type, AsmOperand operand) {
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        if (type instanceof PointerType) {
            return LLVMAddressReadNodeGen.create(frame);
        } else {
            throw new AsmParseException("not a pointer");
        }
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        FrameSlot frame = getArgumentSlot(op.getIndex(), type);
        if (info.isMemory()) {
            return LLVMAddressReadNodeGen.create(frame);
        } else {
            throw new AsmParseException("not a pointer");
        }
    } else if (operand instanceof AsmMemoryOperand) {
        AsmMemoryOperand op = (AsmMemoryOperand) operand;
        int displacement = op.getDisplacement();
        AsmOperand base = op.getBase();
        AsmOperand offset = op.getOffset();
        int shift = op.getShift();
        LLVMExpressionNode baseAddress;
        assert op.getSegment() == null || op.getSegment().equals("%fs");
        LLVMExpressionNode segment = null;
        if (op.getSegment() != null) {
            segment = new LLVMAMD64GetTlsNode();
        }
        if (base != null) {
            baseAddress = getOperandLoad(new PointerType(type), base);
        } else if (offset != null) {
            LLVMExpressionNode offsetNode = getOperandLoad(null, offset);
            if (op.getSegment() != null) {
                return LLVMAMD64AddressOffsetComputationNodeGen.create(displacement, shift, segment, offsetNode);
            } else {
                return LLVMAMD64AddressNoBaseOffsetComputationNodeGen.create(displacement, shift, offsetNode);
            }
        } else if (op.getSegment() != null) {
            return LLVMAMD64AddressDisplacementComputationNodeGen.create(displacement, segment);
        } else {
            if (type instanceof PrimitiveType) {
                switch(((PrimitiveType) type).getPrimitiveKind()) {
                    case I16:
                        return LLVMAMD64I16NodeGen.create((short) displacement);
                    case I32:
                        return LLVMAMD64I32NodeGen.create(displacement);
                    case I64:
                        return LLVMAMD64I64NodeGen.create(displacement);
                    default:
                        throw new AsmParseException("unknown type: " + type);
                }
            } else if (type instanceof PointerType) {
                return LLVMAMD64I64NodeGen.create(displacement);
            } else {
                throw new AsmParseException("invalid type: " + type);
            }
        }
        LLVMExpressionNode address;
        if (offset == null) {
            address = LLVMAMD64AddressDisplacementComputationNodeGen.create(displacement, baseAddress);
        } else {
            LLVMExpressionNode offsetNode = getOperandLoad(null, offset);
            address = LLVMAMD64AddressOffsetComputationNodeGen.create(displacement, shift, baseAddress, offsetNode);
        }
        if (op.getSegment() != null) {
            address = LLVMAMD64AddressSegmentComputationNodeGen.create(address, segment);
        }
        return address;
    } else {
        throw new AsmParseException("unsupported operand: " + operand);
    }
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMAMD64GetTlsNode(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64GetTlsNode) 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 13 with PrimitiveType

use of com.oracle.truffle.llvm.runtime.types.PrimitiveType 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 14 with PrimitiveType

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

the class BasicNodeFactory method createArrayLiteral.

@Override
public LLVMExpressionNode createArrayLiteral(LLVMParserRuntime runtime, List<LLVMExpressionNode> arrayValues, ArrayType arrayType) {
    assert arrayType.getNumberOfElements() == arrayValues.size();
    LLVMExpressionNode arrayAlloc = createAlloca(runtime, arrayType);
    int nrElements = arrayValues.size();
    Type elementType = arrayType.getElementType();
    int elementSize = runtime.getContext().getByteSize(elementType);
    if (elementSize == 0) {
        throw new AssertionError(elementType + " has size of 0!");
    }
    if (elementType instanceof PrimitiveType) {
        switch(((PrimitiveType) elementType).getPrimitiveKind()) {
            case I8:
                return LLVMI8ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I16:
                return LLVMI16ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I32:
                return LLVMI32ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I64:
                return LLVMI64ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case FLOAT:
                return LLVMFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case DOUBLE:
                return LLVMDoubleArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case X86_FP80:
                return LLVM80BitFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            default:
                throw new AssertionError(elementType);
        }
    } else if (Type.isFunctionOrFunctionPointer(elementType)) {
        return LLVMFunctionArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
    } else if (elementType instanceof PointerType) {
        return LLVMAddressArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
    } else if (elementType instanceof ArrayType || elementType instanceof StructureType) {
        return LLVMStructArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), createMemMove(), elementSize, arrayAlloc);
    }
    throw new AssertionError(elementType);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 15 with PrimitiveType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(SwitchOldInstruction zwitch) {
    LLVMExpressionNode cond = symbols.resolve(zwitch.getCondition());
    int[] successors = new int[zwitch.getCaseCount() + 1];
    for (int i = 0; i < successors.length - 1; i++) {
        successors[i] = zwitch.getCaseBlock(i).getBlockIndex();
    }
    successors[successors.length - 1] = zwitch.getDefaultBlock().getBlockIndex();
    final PrimitiveType llvmType = (PrimitiveType) zwitch.getCondition().getType();
    final LLVMExpressionNode[] cases = new LLVMExpressionNode[zwitch.getCaseCount()];
    for (int i = 0; i < cases.length; i++) {
        // casts to smaller types in the factoryfacade won't work
        switch(llvmType.getPrimitiveKind()) {
            case I8:
                cases[i] = nodeFactory.createLiteral(runtime, (byte) zwitch.getCaseValue(i), llvmType);
                break;
            case I16:
                cases[i] = nodeFactory.createLiteral(runtime, (short) zwitch.getCaseValue(i), llvmType);
                break;
            case I32:
                cases[i] = nodeFactory.createLiteral(runtime, (int) zwitch.getCaseValue(i), llvmType);
                break;
            default:
                cases[i] = nodeFactory.createLiteral(runtime, zwitch.getCaseValue(i), llvmType);
        }
    }
    LLVMControlFlowNode node = nodeFactory.createSwitch(runtime, cond, successors, cases, llvmType, getPhiWriteNodes(zwitch), sourceFunction.getSourceLocation(zwitch));
    setControlFlowNode(node);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Aggregations

PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)16 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)12 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)11 Type (com.oracle.truffle.llvm.runtime.types.Type)8 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)8 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)7 PrimitiveKind (com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)5 LLVMUnsupportedInlineAssemblerNode (com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)3 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)3 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)3 FrameSlotKind (com.oracle.truffle.api.frame.FrameSlotKind)2 LLVMAMD64Target (com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64Target)2 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)2 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)2 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)2 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)2 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)2 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)2 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)2