Search in sources :

Example 21 with LLVMExpressionNode

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

the class LLVMParserRuntime method resolveStructor.

private LLVMExpressionNode[] resolveStructor(GlobalValueSymbol globalVar, Comparator<Pair<Integer, ?>> priorityComparator) {
    if (!(globalVar.getValue() instanceof ArrayConstant)) {
        // array globals of length 0 may be initialized with scalar null
        return LLVMExpressionNode.NO_EXPRESSIONS;
    }
    final Object globalVariableDescriptor = scope.getGlobalVariable(globalVar.getName());
    final ArrayConstant arrayConstant = (ArrayConstant) globalVar.getValue();
    final int elemCount = arrayConstant.getElementCount();
    final StructureType elementType = (StructureType) arrayConstant.getType().getElementType();
    final int structSize = getContext().getByteSize(elementType);
    final FunctionType functionType = (FunctionType) ((PointerType) elementType.getElementType(1)).getPointeeType();
    final int indexedTypeLength = getContext().getByteAlignment(functionType);
    final ArrayList<Pair<Integer, LLVMExpressionNode>> structors = new ArrayList<>(elemCount);
    for (int i = 0; i < elemCount; i++) {
        final LLVMExpressionNode globalVarAddress = nodeFactory.createLiteral(this, globalVariableDescriptor, new PointerType(globalVar.getType()));
        final LLVMExpressionNode iNode = nodeFactory.createLiteral(this, i, PrimitiveType.I32);
        final LLVMExpressionNode structPointer = nodeFactory.createTypedElementPointer(this, globalVarAddress, iNode, structSize, elementType);
        final LLVMExpressionNode loadedStruct = nodeFactory.createLoad(this, elementType, structPointer);
        final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(this, 1, PrimitiveType.I32);
        final LLVMExpressionNode functionLoadTarget = nodeFactory.createTypedElementPointer(this, loadedStruct, oneLiteralNode, indexedTypeLength, functionType);
        final LLVMExpressionNode loadedFunction = nodeFactory.createLoad(this, functionType, functionLoadTarget);
        final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[] { nodeFactory.createFrameRead(this, PointerType.VOID, rootFrame.findFrameSlot(LLVMStack.FRAME_ID)) };
        final LLVMExpressionNode functionCall = nodeFactory.createFunctionCall(this, loadedFunction, argNodes, functionType, null);
        final StructureConstant structorDefinition = (StructureConstant) arrayConstant.getElement(i);
        final SymbolImpl prioritySymbol = structorDefinition.getElement(0);
        final Integer priority = LLVMSymbolReadResolver.evaluateIntegerConstant(prioritySymbol);
        structors.add(new Pair<>(priority != null ? priority : LEAST_CONSTRUCTOR_PRIORITY, functionCall));
    }
    return structors.stream().sorted(priorityComparator).map(Pair::getSecond).toArray(LLVMExpressionNode[]::new);
}
Also used : FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) StructureConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant) Pair(com.oracle.truffle.llvm.parser.util.Pair)

Example 22 with LLVMExpressionNode

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

the class LazyToTruffleConverterImpl method convert.

@Override
public RootCallTarget convert() {
    CompilerAsserts.neverPartOfCompilation();
    // parse the function block
    parser.parse(diProcessor, source);
    // prepare the phis
    final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
    // setup the frameDescriptor
    final FrameDescriptor frame = StackManager.createFrame(method);
    LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(frame, context, phis, method);
    LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, frame);
    List<FrameSlot> notNullable = new ArrayList<>();
    LLVMRuntimeDebugInformation dbgInfoHandler = new LLVMRuntimeDebugInformation(frame, nodeFactory, context, notNullable, symbols, runtime);
    dbgInfoHandler.registerStaticDebugSymbols(method);
    LLVMBitcodeFunctionVisitor visitor = new LLVMBitcodeFunctionVisitor(runtime, frame, phis, nodeFactory, method.getParameters().size(), symbols, method, liveness, notNullable, dbgInfoHandler);
    method.accept(visitor);
    FrameSlot[][] nullableBeforeBlock = getNullableFrameSlots(frame, liveness.getNullableBeforeBlock(), notNullable);
    FrameSlot[][] nullableAfterBlock = getNullableFrameSlots(frame, liveness.getNullableAfterBlock(), notNullable);
    LLVMSourceLocation location = method.getLexicalScope();
    List<LLVMExpressionNode> copyArgumentsToFrame = copyArgumentsToFrame(frame);
    LLVMExpressionNode[] copyArgumentsToFrameArray = copyArgumentsToFrame.toArray(new LLVMExpressionNode[copyArgumentsToFrame.size()]);
    LLVMExpressionNode body = nodeFactory.createFunctionBlockNode(runtime, frame.findFrameSlot(LLVMException.FRAME_SLOT_ID), visitor.getBlocks(), nullableBeforeBlock, nullableAfterBlock, location, copyArgumentsToFrameArray);
    RootNode rootNode = nodeFactory.createFunctionStartNode(runtime, body, method.getSourceSection(), frame, method, source, location);
    return Truffle.getRuntime().createCallTarget(rootNode);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) LLVMLivenessAnalysisResult(com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayList(java.util.ArrayList) List(java.util.List) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 23 with LLVMExpressionNode

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

the class BasicNodeFactory method createVectorLiteralNode.

@Override
public LLVMExpressionNode createVectorLiteralNode(LLVMParserRuntime runtime, List<LLVMExpressionNode> listValues, Type type) {
    LLVMExpressionNode[] vals = listValues.toArray(new LLVMExpressionNode[listValues.size()]);
    Type llvmType = ((VectorType) type).getElementType();
    if (llvmType instanceof PrimitiveType) {
        switch(((PrimitiveType) llvmType).getPrimitiveKind()) {
            case I1:
                return LLVMVectorI1LiteralNodeGen.create(vals);
            case I8:
                return LLVMVectorI8LiteralNodeGen.create(vals);
            case I16:
                return LLVMVectorI16LiteralNodeGen.create(vals);
            case I32:
                return LLVMVectorI32LiteralNodeGen.create(vals);
            case I64:
                return LLVMVectorI64LiteralNodeGen.create(vals);
            case FLOAT:
                return LLVMVectorFloatLiteralNodeGen.create(vals);
            case DOUBLE:
                return LLVMVectorDoubleLiteralNodeGen.create(vals);
            default:
                throw new AssertionError();
        }
    } else if (llvmType instanceof PointerType) {
        if (((PointerType) llvmType).getPointeeType() instanceof FunctionType) {
            return LLVMVectorFunctionLiteralNodeGen.create(vals);
        } else {
            return LLVMVectorAddressLiteralNodeGen.create(vals);
        }
    } else {
        throw new AssertionError(llvmType + " not yet supported");
    }
}
Also used : 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) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) 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 24 with LLVMExpressionNode

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

the class AsmFactory method createUnaryOperationImplicitSize.

void createUnaryOperationImplicitSize(String operation, AsmOperand operand) {
    LLVMExpressionNode out;
    AsmOperand dst = operand;
    assert operand != null;
    assert operation.length() > 0;
    Type dstType = getType(operand);
    PrimitiveType.PrimitiveKind dstPrimitiveType = (dstType instanceof PrimitiveType) ? ((PrimitiveType) dstType).getPrimitiveKind() : null;
    switch(operation) {
        case "seta":
        case "setnbe":
            out = LLVMAMD64SetaNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
            dstType = PrimitiveType.I8;
            break;
        case "setae":
        case "setnb":
        case "setnc":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.CF));
            dstType = PrimitiveType.I8;
            break;
        case "setb":
        case "setc":
        case "setnae":
            out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.CF));
            dstType = PrimitiveType.I8;
            break;
        case "setbe":
            out = LLVMAMD64SetorNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
            dstType = PrimitiveType.I8;
            break;
        case "sete":
        case "setz":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.ZF));
            dstType = PrimitiveType.I8;
            break;
        case "setg":
        case "setnle":
            out = LLVMAMD64SetgNodeGen.create(getFlag(LLVMAMD64Flags.ZF), getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setge":
        case "setnl":
            out = LLVMAMD64SeteqNodeGen.create(getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setl":
        case "setnge":
            out = LLVMAMD64SetneNodeGen.create(getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setle":
        case "setng":
            out = LLVMAMD64SetleNodeGen.create(getFlag(LLVMAMD64Flags.ZF), getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setna":
            out = LLVMAMD64SetorNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
            dstType = PrimitiveType.I8;
            break;
        case "setne":
        case "setnz":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.ZF));
            dstType = PrimitiveType.I8;
            break;
        case "setno":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setnp":
        case "setpo":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.PF));
            dstType = PrimitiveType.I8;
            break;
        case "setns":
            out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.SF));
            dstType = PrimitiveType.I8;
            break;
        case "seto":
            out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.OF));
            dstType = PrimitiveType.I8;
            break;
        case "setp":
        case "setpe":
            out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.PF));
            dstType = PrimitiveType.I8;
            break;
        case "sets":
            out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.SF));
            dstType = PrimitiveType.I8;
            break;
        case "rdrand":
            if (dstType instanceof PrimitiveType) {
                switch(dstPrimitiveType) {
                    case I16:
                        out = LLVMAMD64RdRandwNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    case I32:
                        out = LLVMAMD64RdRandlNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    case I64:
                        out = LLVMAMD64RdRandqNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    default:
                        throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "rdseed":
            if (dstType instanceof PrimitiveType) {
                switch(dstPrimitiveType) {
                    case I16:
                        out = LLVMAMD64RdSeedwNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    case I32:
                        out = LLVMAMD64RdSeedlNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    case I64:
                        out = LLVMAMD64RdSeedqNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
                        break;
                    default:
                        throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "pop":
            // default size: I64
            if (dstType == null) {
                dstType = PrimitiveType.I64;
                dstPrimitiveType = PrimitiveKind.I64;
            }
            if (dstType instanceof PrimitiveType) {
                switch(dstPrimitiveType) {
                    case I16:
                        out = LLVMAMD64PopwNodeGen.create();
                        break;
                    case I32:
                        out = LLVMAMD64PoplNodeGen.create();
                        break;
                    case I64:
                        out = LLVMAMD64PopqNodeGen.create();
                        break;
                    default:
                        throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                }
            } else if (dstType instanceof PointerType) {
                PointerType ptr = (PointerType) dstType;
                dstType = ptr.getPointeeType();
                if (dstType instanceof PrimitiveType) {
                    switch(((PrimitiveType) dstType).getPrimitiveKind()) {
                        case I16:
                            out = LLVMAMD64PopwNodeGen.create();
                            break;
                        case I32:
                            out = LLVMAMD64PoplNodeGen.create();
                            break;
                        case I64:
                            out = LLVMAMD64PopqNodeGen.create();
                            break;
                        default:
                            throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                    }
                } else {
                    throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
            break;
        case "push":
            // default size: I64
            if (dstType == null) {
                dstType = PrimitiveType.I64;
                dstPrimitiveType = PrimitiveKind.I64;
            }
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode src = getOperandLoad(dstType, operand);
                switch(dstPrimitiveType) {
                    case I16:
                        statements.add(LLVMAMD64PushwNodeGen.create(src));
                        return;
                    case I32:
                        statements.add(LLVMAMD64PushlNodeGen.create(src));
                        return;
                    case I64:
                        statements.add(LLVMAMD64PushqNodeGen.create(src));
                        return;
                    default:
                        throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                }
            } else if (dstType instanceof PointerType) {
                PointerType ptr = (PointerType) dstType;
                dstType = ptr.getPointeeType();
                LLVMExpressionNode src = getOperandLoad(dstType, operand);
                if (dstType instanceof PrimitiveType) {
                    switch(((PrimitiveType) dstType).getPrimitiveKind()) {
                        case I16:
                            statements.add(LLVMAMD64PushwNodeGen.create(src));
                            return;
                        case I32:
                            statements.add(LLVMAMD64PushlNodeGen.create(src));
                            return;
                        case I64:
                            statements.add(LLVMAMD64PushqNodeGen.create(src));
                            return;
                        default:
                            throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                    }
                } else {
                    throw new AsmParseException("invalid operand type: " + dstType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
        case "bswap":
            if (dstType instanceof PrimitiveType) {
                LLVMExpressionNode src = getOperandLoad(dstType, operand);
                switch(dstPrimitiveType) {
                    case I32:
                        statements.add(LLVMAMD64BswaplNodeGen.create(src));
                        return;
                    case I64:
                        statements.add(LLVMAMD64BswapqNodeGen.create(src));
                        return;
                    default:
                        throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
                }
            } else {
                throw new AsmParseException("invalid operand type: " + dstType);
            }
        default:
            statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
            return;
    }
    if (dstType == null) {
        throw new IllegalArgumentException("unknown operand width");
    }
    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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMUnsupportedInlineAssemblerNode(com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)

Example 25 with LLVMExpressionNode

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

the class AsmFactory method createBinaryOperation.

void createBinaryOperation(String operation, AsmOperand a, AsmOperand b) {
    LLVMExpressionNode srcA;
    LLVMExpressionNode srcB;
    LLVMExpressionNode out;
    assert a != null && b != null;
    AsmOperand dst = b;
    Type dstType;
    char suffix = operation.charAt(operation.length() - 1);
    dstType = getPrimitiveTypeFromSuffix(suffix);
    srcB = getOperandLoad(dstType, b);
    if (isShiftOperation(operation)) {
        srcA = getOperandLoad(PrimitiveType.I8, a);
    } else {
        srcA = getOperandLoad(dstType, a);
    }
    switch(operation) {
        case "addb":
            out = LLVMAMD64AddbNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB);
            break;
        case "addw":
            out = LLVMAMD64AddwNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB);
            break;
        case "addl":
            out = LLVMAMD64AddlNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB);
            break;
        case "addq":
            out = LLVMAMD64AddqNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB);
            break;
        case "adcb":
            out = LLVMAMD64AdcbNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB, getFlag(LLVMAMD64Flags.CF));
            break;
        case "adcw":
            out = LLVMAMD64AdcwNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB, getFlag(LLVMAMD64Flags.CF));
            break;
        case "adcl":
            out = LLVMAMD64AdclNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB, getFlag(LLVMAMD64Flags.CF));
            break;
        case "adcq":
            out = LLVMAMD64AdcqNodeGen.create(getUpdateCPZSOFlagsNode(), srcA, srcB, getFlag(LLVMAMD64Flags.CF));
            break;
        case "subb":
            out = LLVMAMD64SubbNodeGen.create(srcB, srcA);
            break;
        case "subw":
            out = LLVMAMD64SubwNodeGen.create(srcB, srcA);
            break;
        case "subl":
            out = LLVMAMD64SublNodeGen.create(srcB, srcA);
            break;
        case "subq":
            out = LLVMAMD64SubqNodeGen.create(srcB, srcA);
            break;
        case "idivb":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            srcB = getOperandLoad(PrimitiveType.I16, b);
            out = LLVMAMD64IdivbNodeGen.create(srcB, srcA);
            dst = new AsmRegisterOperand("ax");
            dstType = PrimitiveType.I16;
            break;
        case "idivw":
            {
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(getRegisterStore("ax"), getRegisterStore("dx"));
                LLVMExpressionNode high = getOperandLoad(PrimitiveType.I16, new AsmRegisterOperand("dx"));
                out = LLVMAMD64IdivwNodeGen.create(res, high, srcB, srcA);
                statements.add(out);
                return;
            }
        case "idivl":
            {
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(getRegisterStore("eax"), getRegisterStore("edx"));
                LLVMExpressionNode high = getOperandLoad(PrimitiveType.I32, new AsmRegisterOperand("edx"));
                out = LLVMAMD64IdivlNodeGen.create(res, high, srcB, srcA);
                statements.add(out);
                return;
            }
        case "idivq":
            {
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(getRegisterStore("rax"), getRegisterStore("rdx"));
                LLVMExpressionNode high = getOperandLoad(PrimitiveType.I32, new AsmRegisterOperand("rdx"));
                out = LLVMAMD64IdivqNodeGen.create(res, high, srcB, srcA);
                statements.add(out);
                return;
            }
        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;
            }
        case "movb":
        case "movw":
        case "movl":
        case "movq":
            out = srcA;
            break;
        case "movsbw":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI16NoZeroExtNodeGen.create(srcA);
            break;
        case "movsbl":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI32NoZeroExtNodeGen.create(srcA);
            break;
        case "movsbq":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI64NoZeroExtNodeGen.create(srcA);
            break;
        case "movswl":
            srcA = getOperandLoad(PrimitiveType.I16, a);
            out = LLVMToI32NoZeroExtNodeGen.create(srcA);
            break;
        case "movswq":
            srcA = getOperandLoad(PrimitiveType.I16, a);
            out = LLVMToI64NoZeroExtNodeGen.create(srcA);
            break;
        case "movslq":
            srcA = getOperandLoad(PrimitiveType.I32, a);
            out = LLVMToI64NoZeroExtNodeGen.create(srcA);
            break;
        case "movzbw":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI16ZeroExtNodeGen.create(srcA);
            break;
        case "movzbl":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI32ZeroExtNodeGen.create(srcA);
            break;
        case "movzbq":
            srcA = getOperandLoad(PrimitiveType.I8, a);
            out = LLVMToI64ZeroExtNodeGen.create(srcA);
            break;
        case "movzwl":
            srcA = getOperandLoad(PrimitiveType.I16, a);
            out = LLVMToI32ZeroExtNodeGen.create(srcA);
            break;
        case "movzwq":
            srcA = getOperandLoad(PrimitiveType.I16, a);
            out = LLVMToI64ZeroExtNodeGen.create(srcA);
            break;
        case "salb":
            out = LLVMAMD64SalbNodeGen.create(srcB, srcA);
            break;
        case "salw":
            out = LLVMAMD64SalwNodeGen.create(srcB, srcA);
            break;
        case "sall":
            out = LLVMAMD64SallNodeGen.create(srcB, srcA);
            break;
        case "salq":
            out = LLVMAMD64SalqNodeGen.create(srcB, srcA);
            break;
        case "sarb":
            out = LLVMAMD64SarbNodeGen.create(srcB, srcA);
            break;
        case "sarw":
            out = LLVMAMD64SarwNodeGen.create(srcB, srcA);
            break;
        case "sarl":
            out = LLVMAMD64SarlNodeGen.create(srcB, srcA);
            break;
        case "sarq":
            out = LLVMAMD64SarqNodeGen.create(srcB, srcA);
            break;
        case "shlb":
            out = LLVMAMD64ShlbNodeGen.create(srcB, srcA);
            break;
        case "shlw":
            out = LLVMAMD64ShlwNodeGen.create(srcB, srcA);
            break;
        case "shll":
            out = LLVMAMD64ShllNodeGen.create(srcB, srcA);
            break;
        case "shlq":
            out = LLVMAMD64ShlqNodeGen.create(srcB, srcA);
            break;
        case "shrb":
            out = LLVMAMD64ShrbNodeGen.create(srcB, srcA);
            break;
        case "shrw":
            out = LLVMAMD64ShrwNodeGen.create(srcB, srcA);
            break;
        case "shrl":
            out = LLVMAMD64ShrlNodeGen.create(srcB, srcA);
            break;
        case "shrq":
            out = LLVMAMD64ShrqNodeGen.create(srcB, srcA);
            break;
        case "rolb":
            out = LLVMAMD64RolbNodeGen.create(srcB, srcA);
            break;
        case "rolw":
            out = LLVMAMD64RolwNodeGen.create(srcB, srcA);
            break;
        case "roll":
            out = LLVMAMD64RollNodeGen.create(srcB, srcA);
            break;
        case "rolq":
            out = LLVMAMD64RolqNodeGen.create(srcB, srcA);
            break;
        case "rorb":
            out = LLVMAMD64RorbNodeGen.create(srcB, srcA);
            break;
        case "rorw":
            out = LLVMAMD64RorwNodeGen.create(srcB, srcA);
            break;
        case "rorl":
            out = LLVMAMD64RorlNodeGen.create(srcB, srcA);
            break;
        case "rorq":
            out = LLVMAMD64RorqNodeGen.create(srcB, srcA);
            break;
        case "andb":
            out = LLVMAMD64AndbNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
            break;
        case "andw":
            out = LLVMAMD64AndwNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
            break;
        case "andl":
            out = LLVMAMD64AndlNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
            break;
        case "andq":
            out = LLVMAMD64AndqNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
            break;
        case "orb":
            out = LLVMAMD64OrbNodeGen.create(srcA, srcB);
            break;
        case "orw":
            out = LLVMAMD64OrwNodeGen.create(srcA, srcB);
            break;
        case "orl":
            out = LLVMAMD64OrlNodeGen.create(srcA, srcB);
            break;
        case "orq":
            out = LLVMAMD64OrqNodeGen.create(srcA, srcB);
            break;
        case "xchgb":
            {
                XchgOperands operands = new XchgOperands(a, b, dstType);
                out = LLVMAMD64XchgbNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                statements.add(out);
                return;
            }
        case "xchgw":
            {
                XchgOperands operands = new XchgOperands(a, b, dstType);
                out = LLVMAMD64XchgwNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                statements.add(out);
                return;
            }
        case "xchgl":
            {
                XchgOperands operands = new XchgOperands(a, b, dstType);
                out = LLVMAMD64XchglNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                statements.add(out);
                return;
            }
        case "xchgq":
            {
                XchgOperands operands = new XchgOperands(a, b, dstType);
                out = LLVMAMD64XchgqNodeGen.create(operands.dst, operands.srcA, operands.srcB);
                statements.add(out);
                return;
            }
        case "cmpb":
            statements.add(LLVMAMD64CmpbNodeGen.create(getUpdateCPAZSOFlagsNode(), srcB, srcA));
            return;
        case "cmpw":
            statements.add(LLVMAMD64CmpwNodeGen.create(getUpdateCPAZSOFlagsNode(), srcB, srcA));
            return;
        case "cmpl":
            statements.add(LLVMAMD64CmplNodeGen.create(getUpdateCPAZSOFlagsNode(), srcB, srcA));
            return;
        case "cmpq":
            statements.add(LLVMAMD64CmpqNodeGen.create(getUpdateCPAZSOFlagsNode(), srcB, srcA));
            return;
        case "cmpxchgb":
            {
                LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
                LLVMAMD64WriteValueNode dst2 = getRegisterStore("al");
                LLVMExpressionNode accumulator = getOperandLoad(PrimitiveType.I8, new AsmRegisterOperand("al"));
                out = LLVMAMD64CmpXchgbNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                statements.add(out);
                return;
            }
        case "cmpxchgw":
            {
                LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
                LLVMAMD64WriteValueNode dst2 = getRegisterStore("ax");
                LLVMExpressionNode accumulator = getOperandLoad(PrimitiveType.I16, new AsmRegisterOperand("ax"));
                out = LLVMAMD64CmpXchgwNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                statements.add(out);
                return;
            }
        case "cmpxchgl":
            {
                LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
                LLVMAMD64WriteValueNode dst2 = getRegisterStore("eax");
                LLVMExpressionNode accumulator = getOperandLoad(PrimitiveType.I32, new AsmRegisterOperand("eax"));
                out = LLVMAMD64CmpXchglNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                statements.add(out);
                return;
            }
        case "cmpxchgq":
            {
                LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
                LLVMAMD64WriteValueNode dst2 = getRegisterStore("rax");
                LLVMExpressionNode accumulator = getOperandLoad(PrimitiveType.I64, new AsmRegisterOperand("rax"));
                out = LLVMAMD64CmpXchgqNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
                statements.add(out);
                return;
            }
        case "xaddb":
            {
                LLVMAMD64WriteValueNode dst1 = getRegisterStore(PrimitiveType.I8, a);
                LLVMAMD64WriteValueNode dst2 = getStore(dstType, dst);
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(dst1, dst2);
                out = LLVMAMD64XaddbNodeGen.create(getUpdateCPZSOFlagsNode(), res, srcA, srcB);
                statements.add(out);
                return;
            }
        case "xaddw":
            {
                LLVMAMD64WriteValueNode dst1 = getRegisterStore(PrimitiveType.I16, a);
                LLVMAMD64WriteValueNode dst2 = getStore(dstType, dst);
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(dst1, dst2);
                out = LLVMAMD64XaddwNodeGen.create(getUpdateCPZSOFlagsNode(), res, srcA, srcB);
                statements.add(out);
                return;
            }
        case "xaddl":
            {
                LLVMAMD64WriteValueNode dst1 = getRegisterStore(PrimitiveType.I32, a);
                LLVMAMD64WriteValueNode dst2 = getStore(dstType, dst);
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(dst1, dst2);
                out = LLVMAMD64XaddlNodeGen.create(getUpdateCPZSOFlagsNode(), res, srcA, srcB);
                statements.add(out);
                return;
            }
        case "xaddq":
            {
                LLVMAMD64WriteValueNode dst1 = getRegisterStore(PrimitiveType.I64, a);
                LLVMAMD64WriteValueNode dst2 = getStore(dstType, dst);
                LLVMAMD64WriteTupelNode res = LLVMAMD64WriteTupelNodeGen.create(dst1, dst2);
                out = LLVMAMD64XaddqNodeGen.create(getUpdateCPZSOFlagsNode(), res, srcA, srcB);
                statements.add(out);
                return;
            }
        case "xorb":
            out = LLVMAMD64XorbNodeGen.create(srcA, srcB);
            break;
        case "xorw":
            out = LLVMAMD64XorwNodeGen.create(srcA, srcB);
            break;
        case "xorl":
            out = LLVMAMD64XorlNodeGen.create(srcA, srcB);
            break;
        case "xorq":
            out = LLVMAMD64XorqNodeGen.create(srcA, srcB);
            break;
        case "bsrw":
            out = LLVMAMD64BsrwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        case "bsrl":
            out = LLVMAMD64BsrlNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        case "bsrq":
            out = LLVMAMD64BsrqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        case "bsfw":
            out = LLVMAMD64BsfwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        case "bsfl":
            out = LLVMAMD64BsflNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        case "bsfq":
            out = LLVMAMD64BsfqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
            break;
        default:
            statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
            return;
    }
    LLVMExpressionNode write = getOperandStore(dstType, dst, out);
    statements.add(write);
}
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) LLVMAMD64WriteValueNode(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64WriteValueNode) LLVMAMD64WriteTupelNode(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64WriteTupelNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMUnsupportedInlineAssemblerNode(com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)

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