Search in sources :

Example 6 with Type

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

the class ParseUtil method resolveSymbol.

static MDBaseNode resolveSymbol(long[] args, int index, Metadata md) {
    final int typeIndex = index << 1;
    if (typeIndex >= args.length) {
        return MDVoidNode.INSTANCE;
    }
    final int valueIndex = typeIndex + 1;
    final Type type = md.getTypeById(args[typeIndex]);
    final long value = (int) args[valueIndex];
    if (type != MetaType.METADATA && !VoidType.INSTANCE.equals(type)) {
        return MDValue.create(value, md.getScope());
    } else {
        return MDVoidNode.INSTANCE;
    }
}
Also used : Type(com.oracle.truffle.llvm.runtime.types.Type) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType)

Example 7 with Type

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

the class ParseUtil method asLong.

public static long asLong(long[] args, int index, Metadata md) {
    final int typeIndex = index << 1;
    if (typeIndex >= args.length) {
        return DEFAULT_NUMBER;
    }
    final Type type = md.getTypeById(args[typeIndex]);
    if (type == MetaType.METADATA || VoidType.INSTANCE.equals(type)) {
        return DEFAULT_NUMBER;
    }
    final int valueIndex = typeIndex + 1;
    final SymbolImpl value = md.getScope().getSymbols().getOrNull((int) args[valueIndex]);
    if (value instanceof IntegerConstant) {
        return ((IntegerConstant) value).getValue();
    } else if (value instanceof BigIntegerConstant) {
        return ((BigIntegerConstant) value).getValue().longValue();
    } else if (value instanceof NullConstant || value instanceof UndefinedConstant) {
        return 0L;
    } else {
        return DEFAULT_NUMBER;
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) Type(com.oracle.truffle.llvm.runtime.types.Type) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) IntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant)

Example 8 with Type

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

the class AggregateConstant method fromData.

public static AggregateConstant fromData(Type type, long[] data) {
    final AggregateConstant aggregateConstant;
    final Type elementType;
    if (type instanceof ArrayType) {
        final ArrayType arrayType = (ArrayType) type;
        elementType = arrayType.getElementType();
        aggregateConstant = new ArrayConstant(arrayType, data.length);
    } else if (type instanceof VectorType) {
        final VectorType vectorType = (VectorType) type;
        elementType = vectorType.getElementType();
        aggregateConstant = new VectorConstant((VectorType) type, data.length);
    } else {
        throw new RuntimeException("Cannot create constant from data: " + type);
    }
    for (int i = 0; i < data.length; i++) {
        aggregateConstant.elements[i] = Constant.createFromData(elementType, data[i]);
    }
    return aggregateConstant;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType)

Example 9 with Type

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(LandingpadInstruction landingpadInstruction) {
    Type type = landingpadInstruction.getType();
    LLVMExpressionNode allocateLandingPadValue = nodeFactory.createAlloca(runtime, type);
    LLVMExpressionNode[] entries = new LLVMExpressionNode[landingpadInstruction.getClauseSymbols().length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = symbols.resolve(landingpadInstruction.getClauseSymbols()[i]);
    }
    LLVMExpressionNode getStack = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    LLVMExpressionNode landingPad = nodeFactory.createLandingPad(runtime, allocateLandingPadValue, getExceptionSlot(), landingpadInstruction.isCleanup(), landingpadInstruction.getClauseTypes(), entries, getStack);
    createFrameWrite(landingPad, landingpadInstruction);
}
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 10 with Type

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InvokeInstruction 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;
    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++, argIndex++) {
        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);
        }
    }
    final SymbolImpl target = call.getCallTarget();
    int regularIndex = call.normalSuccessor().getBlockIndex();
    int unwindIndex = call.unwindSuccessor().getBlockIndex();
    List<FrameSlot> normalTo = new ArrayList<>();
    List<FrameSlot> unwindTo = new ArrayList<>();
    List<Type> normalType = new ArrayList<>();
    List<Type> unwindType = new ArrayList<>();
    List<LLVMExpressionNode> normalValue = new ArrayList<>();
    List<LLVMExpressionNode> unwindValue = new ArrayList<>();
    if (blockPhis != null) {
        for (Phi phi : blockPhis) {
            FrameSlot slot = getSlot(phi.getPhiValue().getName());
            LLVMExpressionNode value = symbols.resolve(phi.getValue());
            if (call.normalSuccessor() == phi.getBlock()) {
                normalTo.add(slot);
                normalType.add(phi.getValue().getType());
                normalValue.add(value);
            } else {
                unwindTo.add(slot);
                unwindType.add(phi.getValue().getType());
                unwindValue.add(value);
            }
        }
    }
    LLVMExpressionNode normalPhi = nodeFactory.createPhi(runtime, normalValue.toArray(new LLVMExpressionNode[normalValue.size()]), normalTo.toArray(new FrameSlot[normalTo.size()]), normalType.toArray(Type.EMPTY_ARRAY));
    LLVMExpressionNode unwindPhi = nodeFactory.createPhi(runtime, unwindValue.toArray(new LLVMExpressionNode[unwindValue.size()]), unwindTo.toArray(new FrameSlot[unwindTo.size()]), unwindType.toArray(Type.EMPTY_ARRAY));
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    LLVMExpressionNode function = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, null);
    if (function == null) {
        function = symbols.resolve(target);
    }
    LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, getSlot(call.getName()), function, argNodes, new FunctionType(targetType, argTypes, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
    setControlFlowNode(result);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Aggregations

Type (com.oracle.truffle.llvm.runtime.types.Type)76 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)68 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)64 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)63 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)57 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)54 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)50 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)43 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)33 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)32 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)28 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)28 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)13 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)9 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)8 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)8 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)6 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)6 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)5 LLVMUnsupportedInlineAssemblerNode (com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)5