Search in sources :

Example 26 with PointerType

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

the class Function method createAtomicReadModifyWrite.

private void createAtomicReadModifyWrite(long[] args) {
    int i = 0;
    final int ptr = getIndex(args[i++]);
    final Type ptrType;
    if (scope.isValueForwardRef(ptr)) {
        ptrType = types.get(args[i++]);
    } else {
        ptrType = scope.getValueType(ptr);
    }
    final int value = getIndex(args[i++]);
    final int opcode = (int) args[i++];
    final boolean isVolatile = args[i++] != 0;
    final long atomicOrdering = args[i++];
    final long synchronizationScope = args[i];
    final Type type = ((PointerType) ptrType).getPointeeType();
    emit(ReadModifyWriteInstruction.fromSymbols(scope.getSymbols(), type, ptr, value, opcode, isVolatile, atomicOrdering, synchronizationScope));
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 27 with PointerType

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

the class Module method createGlobalVariable.

private void createGlobalVariable(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    final long typeField = args[GLOBALVAR_TYPE + recordOffset];
    final long flagField = args[GLOBALVAR_FLAGS + recordOffset];
    Type type = types.get(typeField);
    if ((flagField & GLOBALVAR_EXPLICICTTYPE_MASK) != 0) {
        type = new PointerType(type);
    }
    final boolean isConstant = (flagField & GLOBALVAR_ISCONSTANT_MASK) != 0;
    final int initialiser = (int) args[GLOBALVAR_INTITIALIZER + recordOffset];
    final long linkage = args[GLOBALVAR_LINKAGE + recordOffset];
    final int align = (int) args[GLOBALVAR_ALIGN + recordOffset];
    long visibility = Visibility.DEFAULT.getEncodedValue();
    if (GLOBALVAR_VISIBILITY + recordOffset < args.length) {
        visibility = args[GLOBALVAR_VISIBILITY + recordOffset];
    }
    final GlobalValueSymbol global;
    if (isConstant) {
        global = GlobalConstant.create(type, align, linkage, visibility, scope.getSymbols(), initialiser);
    } else {
        global = GlobalVariable.create(type, align, linkage, visibility, scope.getSymbols(), initialiser);
    }
    if (useStrTab()) {
        readNameFromStrTab(args, global);
    }
    module.addGlobalSymbol(global);
    scope.addSymbol(global, global.getType());
}
Also used : PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)

Example 28 with PointerType

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

the class Module method createGlobalAliasNew.

private void createGlobalAliasNew(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    final Type type = new PointerType(types.get(args[GLOBALALIAS_TYPE + recordOffset]));
    // idx = 1 is address space information
    final int value = (int) args[GLOBALALIAS_NEW_VALUE + recordOffset];
    final long linkage = args[GLOBALALIAS_NEW_LINKAGE + recordOffset];
    final GlobalAlias global = GlobalAlias.create(type, linkage, Visibility.DEFAULT.ordinal(), scope.getSymbols(), value);
    if (useStrTab()) {
        readNameFromStrTab(args, global);
    }
    module.addGlobalSymbol(global);
    scope.addSymbol(global, global.getType());
}
Also used : PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)

Example 29 with PointerType

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

the class BasicNodeFactory method createArrayLiteral.

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

Example 30 with PointerType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ExtractValueInstruction extract) {
    if (!(extract.getAggregate().getType() instanceof ArrayType || extract.getAggregate().getType() instanceof StructureType || extract.getAggregate().getType() instanceof PointerType)) {
        throw new IllegalStateException("\'extractvalue\' can only extract elements of arrays and structs!");
    }
    final LLVMExpressionNode baseAddress = symbols.resolve(extract.getAggregate());
    final Type baseType = extract.getAggregate().getType();
    final int targetIndex = extract.getIndex();
    final Type resultType = extract.getType();
    LLVMExpressionNode targetAddress = baseAddress;
    final AggregateType aggregateType = (AggregateType) baseType;
    long offset = runtime.getContext().getIndexOffset(targetIndex, aggregateType);
    final Type targetType = aggregateType.getElementType(targetIndex);
    if (targetType != null && !((targetType instanceof StructureType) && (((StructureType) targetType).isPacked()))) {
        offset += runtime.getContext().getBytePadding(offset, targetType);
    }
    if (offset != 0) {
        final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(runtime, 1, PrimitiveType.I32);
        targetAddress = nodeFactory.createTypedElementPointer(runtime, targetAddress, oneLiteralNode, offset, extract.getType());
    }
    final LLVMExpressionNode result = nodeFactory.createExtractValue(runtime, resultType, targetAddress);
    createFrameWrite(result, extract);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Aggregations

PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)37 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)31 Type (com.oracle.truffle.llvm.runtime.types.Type)29 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)27 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)24 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)20 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)18 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)18 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)18 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)14 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)9 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)9 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)9 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)6 ArrayList (java.util.ArrayList)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 PrimitiveKind (com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)4 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)4 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)3