Search in sources :

Example 6 with AttributesGroup

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.

the class ParameterAttributes method decodeCodeEntry.

private void decodeCodeEntry(long[] args) {
    final List<AttributesGroup> attrGroup = new ArrayList<>();
    for (long groupId : args) {
        for (AttributesGroup attr : attributes) {
            if (attr.getGroupId() == groupId) {
                attrGroup.add(attr);
                break;
            }
        }
    }
    if (attrGroup.size() != args.length) {
        throw new AssertionError("there is a mismatch between defined and found group id's");
    }
    parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Also used : AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) ArrayList(java.util.ArrayList)

Example 7 with AttributesGroup

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.

the class ParameterAttributes method decodeOldGroupCodeEntry.

private static AttributesGroup decodeOldGroupCodeEntry(long paramIdx, long attr) {
    AttributesGroup group = new AttributesGroup(-1, paramIdx);
    if ((attr & (1L << 0)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.ZEROEXT));
    }
    if ((attr & (1L << 1)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.SIGNEXT));
    }
    if ((attr & (1L << 2)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NORETURN));
    }
    if ((attr & (1L << 3)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.INREG));
    }
    if ((attr & (1L << 4)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.SRET));
    }
    if ((attr & (1L << 5)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOUNWIND));
    }
    if ((attr & (1L << 6)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOALIAS));
    }
    if ((attr & (1L << 7)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.BYVAL));
    }
    if ((attr & (1L << 8)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NEST));
    }
    if ((attr & (1L << 9)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.READNONE));
    }
    if ((attr & (1L << 10)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.READONLY));
    }
    if ((attr & (1L << 11)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOINLINE));
    }
    if ((attr & (1L << 12)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.ALWAYSINLINE));
    }
    if ((attr & (1L << 13)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.OPTSIZE));
    }
    if ((attr & (1L << 14)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.SSP));
    }
    if ((attr & (1L << 15)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.SSPREQ));
    }
    if ((attr & (0xFFL << 16)) != 0) {
        final int align = (int) ((attr >> 16) & 0xFFL);
        group.addAttribute(new Attribute.KnownIntegerValueAttribute(Attribute.Kind.ALIGN, align));
    }
    if ((attr & (1L << 32)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOCAPTURE));
    }
    if ((attr & (1L << 33)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOREDZONE));
    }
    if ((attr & (1L << 34)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NOIMPLICITFLOAT));
    }
    if ((attr & (1L << 35)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.NAKED));
    }
    if ((attr & (1L << 36)) != 0) {
        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.INLINEHINT));
    }
    if ((attr & (0x07L << 37)) != 0) {
        final int alignstack = 1 << ((int) ((attr >> 37) & 0x07L) - 1);
        group.addAttribute(new Attribute.KnownIntegerValueAttribute(Attribute.Kind.ALIGNSTACK, alignstack));
    }
    return group;
}
Also used : AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) Attribute(com.oracle.truffle.llvm.parser.model.attributes.Attribute)

Example 8 with AttributesGroup

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup 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 9 with AttributesGroup

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidInvokeInstruction call) {
    final SymbolImpl target = call.getCallTarget();
    // stackpointer
    final int argumentCount = call.getArgumentCount() + 1;
    final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
    final Type[] argsType = new Type[argumentCount];
    int argIndex = 0;
    args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    argsType[argIndex] = new PointerType(null);
    argIndex++;
    for (int i = 0; i < call.getArgumentCount(); i++) {
        args[argIndex] = symbols.resolve(call.getArgument(i));
        argsType[argIndex] = call.getArgument(i).getType();
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
        }
        argIndex++;
    }
    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, args, argCount, null);
    if (function == null) {
        function = symbols.resolve(target);
    }
    LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, null, function, args, new FunctionType(call.getType(), argsType, 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Aggregations

AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)9 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)4 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)4 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)4 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)4 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)4 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)4 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)4 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)4 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)4 Type (com.oracle.truffle.llvm.runtime.types.Type)4 ArrayList (java.util.ArrayList)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)2 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)2 InlineAsmConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant)2 LLVMControlFlowNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode)2 Attribute (com.oracle.truffle.llvm.parser.model.attributes.Attribute)1