Search in sources :

Example 41 with LLVMExpressionNode

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ExtractElementInstruction extract) {
    LLVMExpressionNode vector = symbols.resolve(extract.getVector());
    LLVMExpressionNode index = symbols.resolve(extract.getIndex());
    Type resultType = extract.getType();
    LLVMExpressionNode result = nodeFactory.createExtractElement(runtime, resultType, vector, index);
    createFrameWrite(result, extract);
}
Also used : LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 42 with LLVMExpressionNode

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(CallInstruction call) {
    final Type targetType = call.getType();
    int argumentCount = getArgumentCount(call.getArgumentCount(), targetType);
    final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
    final Type[] argTypes = new Type[argumentCount];
    int argIndex = 0;
    // stack pointer
    argNodes[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    argTypes[argIndex] = new PointerType(null);
    argIndex++;
    if (targetType instanceof StructureType) {
        argTypes[argIndex] = new PointerType(targetType);
        argNodes[argIndex] = nodeFactory.createAlloca(runtime, targetType);
        argIndex++;
    }
    for (int i = 0; argIndex < argumentCount; i++) {
        argNodes[argIndex] = symbols.resolve(call.getArgument(i));
        argTypes[argIndex] = call.getArgument(i).getType();
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            argNodes[argIndex] = capsuleAddressByValue(argNodes[argIndex], argTypes[argIndex], paramAttr);
        }
        argIndex++;
    }
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    final SymbolImpl target = call.getCallTarget();
    LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, source);
    if (result == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, targetType, source);
        } else {
            LLVMExpressionNode function = symbols.resolve(target);
            result = nodeFactory.createFunctionCall(runtime, function, argNodes, new FunctionType(targetType, argTypes, false), source);
        }
    }
    // the SourceSection references the call, not the return value assignment
    createFrameWrite(result, call, null);
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) InlineAsmConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant)

Example 43 with LLVMExpressionNode

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(SelectInstruction select) {
    final LLVMExpressionNode condition = symbols.resolve(select.getCondition());
    final LLVMExpressionNode trueValue = symbols.resolve(select.getTrueValue());
    final LLVMExpressionNode falseValue = symbols.resolve(select.getFalseValue());
    final Type type = select.getType();
    final LLVMExpressionNode result = nodeFactory.createSelect(runtime, type, condition, trueValue, falseValue);
    createFrameWrite(result, select);
}
Also used : LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 44 with LLVMExpressionNode

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InsertElementInstruction insert) {
    final LLVMExpressionNode vector = symbols.resolve(insert.getVector());
    final LLVMExpressionNode index = symbols.resolve(insert.getIndex());
    final LLVMExpressionNode element = symbols.resolve(insert.getValue());
    final Type type = insert.getType();
    final LLVMExpressionNode result = nodeFactory.createInsertElement(runtime, type, vector, element, index);
    createFrameWrite(result, insert);
}
Also used : LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 45 with LLVMExpressionNode

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

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