Search in sources :

Example 26 with LLVMExpressionNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.

the class AsmFactory method getTarget.

private LLVMAMD64Target getTarget(Type type, AsmOperand operand) {
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        int shift = op.getShift();
        assert type == op.getType();
        switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
            case I8:
                return new LLVMAMD64Target(frame, shift);
            case I16:
            case I32:
            case I64:
                return new LLVMAMD64Target(frame);
            default:
                throw new AsmParseException("unsupported operand type: " + op.getType());
        }
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        if (info.isMemory()) {
            LLVMExpressionNode address = info.getAddress();
            if (type instanceof PointerType) {
                return new LLVMAMD64Target(address);
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                case I16:
                case I32:
                case I64:
                    return new LLVMAMD64Target(address);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (info.isRegister()) {
            FrameSlot frame = getRegisterSlot(info.getRegister());
            if (type instanceof PointerType || info.getType() instanceof PointerType) {
                return new LLVMAMD64Target(frame);
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                case I16:
                case I32:
                case I64:
                    return new LLVMAMD64Target(frame);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else {
            throw new AssertionError("this should not happen; " + info);
        }
    }
    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) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMAMD64Target(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64Target)

Example 27 with LLVMExpressionNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.

the class AsmFactory method createBinaryOperationImplicitSize.

void createBinaryOperationImplicitSize(String operation, AsmOperand a, AsmOperand b) {
    AsmOperand dst = b;
    AsmOperand src = a;
    assert a != null && b != null;
    Type dstType = getType(b, a);
    PrimitiveType.PrimitiveKind dstPrimitiveType = (dstType instanceof PrimitiveType) ? ((PrimitiveType) dstType).getPrimitiveKind() : null;
    LLVMExpressionNode out;
    switch(operation) {
        case "lea":
            out = getOperandAddress(dstType, src);
            if (isLeaPointer(src)) {
                dstType = new PointerType(dstType);
            }
            break;
        case "xor":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                switch(dstPrimitiveType) {
                    case I8:
                        out = LLVMAMD64XorbNodeGen.create(srcA, srcB);
                        break;
                    case I16:
                        out = LLVMAMD64XorwNodeGen.create(srcA, srcB);
                        break;
                    case I32:
                        out = LLVMAMD64XorlNodeGen.create(srcA, srcB);
                        break;
                    case I64:
                        out = LLVMAMD64XorqNodeGen.create(srcA, srcB);
                        break;
                    default:
                        throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "mov":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                out = srcA;
            } else if (dstType instanceof PointerType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                out = srcA;
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "bsr":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                switch(dstPrimitiveType) {
                    case I16:
                        out = LLVMAMD64BsrwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    case I32:
                        out = LLVMAMD64BsrlNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    case I64:
                        out = LLVMAMD64BsrqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    default:
                        throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "bsf":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                switch(dstPrimitiveType) {
                    case I16:
                        out = LLVMAMD64BsfwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    case I32:
                        out = LLVMAMD64BsflNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    case I64:
                        out = LLVMAMD64BsfqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
                        break;
                    default:
                        throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "xchg":
            {
                if (dstType instanceof PrimitiveType) {
                    XchgOperands operands = new XchgOperands(a, b, dstType);
                    switch(dstPrimitiveType) {
                        case I8:
                            out = LLVMAMD64XchgbNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                            break;
                        case I16:
                            out = LLVMAMD64XchgwNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                            break;
                        case I32:
                            out = LLVMAMD64XchglNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                            break;
                        case I64:
                            out = LLVMAMD64XchgqNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                            break;
                        default:
                            throw new AsmParseException("invalid operand type: " + dstType);
                    }
                    statements.add(out);
                    return;
                } else {
                    throw new AsmParseException("invalid operand type: " + dstType);
                }
            }
        case "cmpxchg":
            {
                if (dstType instanceof PointerType) {
                    // treat pointers as I64
                    dstPrimitiveType = PrimitiveKind.I64;
                }
                if (dstType instanceof PrimitiveType || dstType instanceof PointerType) {
                    LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                    LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                    LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
                    LLVMAMD64WriteValueNode dst2;
                    LLVMExpressionNode accumulator;
                    if (dstType instanceof PointerType) {
                        dst2 = getRegisterStore("rax");
                        accumulator = getOperandLoad(new PointerType(PrimitiveType.I8), new AsmRegisterOperand("rax"));
                        out = LLVMAMD64CmpXchgqNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                    } else {
                        switch(dstPrimitiveType) {
                            case I8:
                                dst2 = getRegisterStore("al");
                                accumulator = getOperandLoad(PrimitiveType.I8, new AsmRegisterOperand("al"));
                                out = LLVMAMD64CmpXchgbNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                                break;
                            case I16:
                                dst2 = getRegisterStore("ax");
                                accumulator = getOperandLoad(PrimitiveType.I16, new AsmRegisterOperand("ax"));
                                out = LLVMAMD64CmpXchgwNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                                break;
                            case I32:
                                dst2 = getRegisterStore("eax");
                                accumulator = getOperandLoad(PrimitiveType.I32, new AsmRegisterOperand("eax"));
                                out = LLVMAMD64CmpXchglNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                                break;
                            case I64:
                                dst2 = getRegisterStore("rax");
                                accumulator = getOperandLoad(PrimitiveType.I64, new AsmRegisterOperand("rax"));
                                out = LLVMAMD64CmpXchgqNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                                break;
                            default:
                                throw new AsmParseException("invalid operand type: " + dstType);
                        }
                    }
                    statements.add(out);
                    return;
                } else {
                    throw new AsmParseException("invalid operand type: " + dstType);
                }
            }
        case "and":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                switch(dstPrimitiveType) {
                    case I8:
                        out = LLVMAMD64AndbNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
                        break;
                    case I16:
                        out = LLVMAMD64AndwNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
                        break;
                    case I32:
                        out = LLVMAMD64AndlNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
                        break;
                    case I64:
                        out = LLVMAMD64AndqNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
                        break;
                    default:
                        throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "or":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode srcA = getOperandLoad(dstType, a);
                LLVMExpressionNode srcB = getOperandLoad(dstType, b);
                switch(dstPrimitiveType) {
                    case I8:
                        out = LLVMAMD64OrbNodeGen.create(srcA, srcB);
                        break;
                    case I16:
                        out = LLVMAMD64OrwNodeGen.create(srcA, srcB);
                        break;
                    case I32:
                        out = LLVMAMD64OrlNodeGen.create(srcA, srcB);
                        break;
                    case I64:
                        out = LLVMAMD64OrqNodeGen.create(srcA, srcB);
                        break;
                    default:
                        throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        default:
            statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
            return;
    }
    LLVMExpressionNode write = getOperandStore(dstType, dst, out);
    statements.add(write);
}
Also used : PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind) 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) LLVMAMD64WriteValueNode(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64WriteValueNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMUnsupportedInlineAssemblerNode(com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)

Example 28 with LLVMExpressionNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.

the class AsmFactory method createTernaryOperation.

void createTernaryOperation(String operation, AsmOperand a, AsmOperand b, AsmOperand c) {
    AsmOperand dst = c;
    LLVMExpressionNode srcA;
    LLVMExpressionNode srcB;
    LLVMExpressionNode out;
    Type dstType;
    assert a != null && b != null && c != null;
    char suffix = operation.charAt(operation.length() - 1);
    dstType = getPrimitiveTypeFromSuffix(suffix);
    srcB = getOperandLoad(dstType, b);
    srcA = getOperandLoad(dstType, a);
    @SuppressWarnings("unused") PrimitiveType.PrimitiveKind dstPrimitiveType = (dstType instanceof PrimitiveType) ? ((PrimitiveType) dstType).getPrimitiveKind() : null;
    switch(operation) {
        case "imulw":
            out = LLVMAMD64Imulw3NodeGen.create(getFlagWrite(LLVMAMD64Flags.CF), getFlagWrite(LLVMAMD64Flags.PF), getFlagWrite(LLVMAMD64Flags.AF), getFlagWrite(LLVMAMD64Flags.ZF), getFlagWrite(LLVMAMD64Flags.SF), getFlagWrite(LLVMAMD64Flags.OF), srcA, srcB);
            break;
        case "imull":
            out = LLVMAMD64Imull3NodeGen.create(getFlagWrite(LLVMAMD64Flags.CF), getFlagWrite(LLVMAMD64Flags.PF), getFlagWrite(LLVMAMD64Flags.AF), getFlagWrite(LLVMAMD64Flags.ZF), getFlagWrite(LLVMAMD64Flags.SF), getFlagWrite(LLVMAMD64Flags.OF), srcA, srcB);
            break;
        case "imulq":
            out = LLVMAMD64Imulq3NodeGen.create(getFlagWrite(LLVMAMD64Flags.CF), getFlagWrite(LLVMAMD64Flags.PF), getFlagWrite(LLVMAMD64Flags.AF), getFlagWrite(LLVMAMD64Flags.ZF), getFlagWrite(LLVMAMD64Flags.SF), getFlagWrite(LLVMAMD64Flags.OF), srcA, srcB);
            break;
        default:
            statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
            return;
    }
    LLVMExpressionNode write = getOperandStore(dstType, dst, out);
    statements.add(write);
}
Also used : PrimitiveKind(com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind) 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMUnsupportedInlineAssemblerNode(com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)

Example 29 with LLVMExpressionNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode 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 30 with LLVMExpressionNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode 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)

Aggregations

LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)53 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)39 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)38 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)35 Type (com.oracle.truffle.llvm.runtime.types.Type)33 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)27 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)26 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)24 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)24 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)24 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)12 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)11 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)8 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)7 LLVMControlFlowNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode)7 ArrayList (java.util.ArrayList)7 LLVMUnsupportedInlineAssemblerNode (com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)5 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)4 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)4