Search in sources :

Example 1 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidInvokeInstruction call) {
    final SymbolImpl target = call.getCallTarget();
    if (call.getOperandBundle() != null) {
        throw new LLVMParserException("Unsupported operand bundle on invoke of " + target.toString());
    }
    // stackpointer
    final int argumentCount = call.getArgumentCount() + 1;
    final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
    final TypeArrayBuilder argsType = new TypeArrayBuilder(argumentCount);
    int argIndex = 0;
    args[argIndex] = nodeFactory.createGetStackFromFrame();
    argsType.set(argIndex, new PointerType(null));
    argIndex++;
    int realArgumentCount = call.getCallTarget().getType() instanceof FunctionType ? ((FunctionType) call.getCallTarget().getType()).getNumberOfArguments() : argumentCount;
    for (int i = call.getArgumentCount() - 1; i >= 0; i--) {
        args[argIndex + i] = symbols.resolve(call.getArgument(i));
        argsType.set(argIndex + i, call.getArgument(i).getType());
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        boolean isVarArg = i >= realArgumentCount;
        if (isByValue(paramAttr)) {
            args[argIndex + i] = capsuleAddressByValue(args[argIndex + i], argsType.get(argIndex + i), paramAttr);
        } else if (isVarArg && isArrayByValue(argsType.get(argIndex + i), args[argIndex + i])) {
            args[argIndex + i] = capsuleArrayByValue(args[argIndex + i], argsType.get(argIndex + i));
        }
    }
    int regularIndex = call.normalSuccessor().getBlockIndex();
    int unwindIndex = call.unwindSuccessor().getBlockIndex();
    ArrayList<Phi> normalTo = new ArrayList<>();
    ArrayList<Phi> unwindTo = new ArrayList<>();
    if (blockPhis != null) {
        for (LLVMPhiManager.Phi phi : blockPhis) {
            if (call.normalSuccessor() == phi.getBlock()) {
                normalTo.add(phi);
            } else {
                unwindTo.add(phi);
            }
        }
    }
    LLVMStatementNode normalPhi = createPhiWriteNodes(normalTo);
    LLVMStatementNode unwindPhi = createPhiWriteNodes(unwindTo);
    // Builtins are not AST-inlined for Invokes, instead a generic LLVMDispatchNode is used.
    LLVMExpressionNode function = resolveOptimized(target, call.getArguments());
    LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(null, function, args, new FunctionType(call.getType(), argsType, false), regularIndex, unwindIndex, normalPhi, unwindPhi);
    setControlFlowNode(result, call, SourceInstrumentationStrategy.FORCED);
}
Also used : LLVMPhiManager(com.oracle.truffle.llvm.parser.LLVMPhiManager) LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) TypeArrayBuilder(com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder) LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 2 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidCallInstruction call) {
    // stackpointer
    final int argumentCount = call.getArgumentCount() + 1;
    final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
    final TypeArrayBuilder argTypes = new TypeArrayBuilder(argumentCount);
    int argIndex = 0;
    argNodes[argIndex] = nodeFactory.createGetStackFromFrame();
    argTypes.set(argIndex, new PointerType(null));
    argIndex++;
    SymbolImpl target = call.getCallTarget();
    int realArgumentCount = call.getCallTarget().getType() instanceof FunctionType ? ((FunctionType) call.getCallTarget().getType()).getNumberOfArguments() : argumentCount;
    for (int i = call.getArgumentCount() - 1; i >= 0; i--) {
        argNodes[argIndex + i] = resolveOptimized(call.getArgument(i), i, target, call.getArguments());
        argTypes.set(argIndex + i, call.getArgument(i).getType());
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        boolean isVarArg = i >= realArgumentCount;
        if (isByValue(paramAttr)) {
            argNodes[argIndex + i] = capsuleAddressByValue(argNodes[argIndex + i], argTypes.get(argIndex + i), paramAttr);
        } else if (isVarArg && isArrayByValue(argTypes.get(argIndex + i), argNodes[argIndex + i])) {
            argNodes[argIndex + i] = capsuleArrayByValue(argNodes[argIndex + i], argTypes.get(argIndex + i));
        }
    }
    LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(target, argNodes, argTypes, argCount);
    if (call.getOperandBundle() != null && !(result instanceof LLVMAssume)) {
        throw new LLVMParserException("Unsupported operand bundle on call of " + target.toString());
    }
    SourceInstrumentationStrategy intent = SourceInstrumentationStrategy.ONLY_FIRST_STATEMENT_ON_LOCATION;
    if (result == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, call.getType());
            assignSourceLocation(result, call);
        } else {
            final LLVMExpressionNode function = resolveOptimized(target, call.getArguments());
            final FunctionType functionType = new FunctionType(call.getType(), argTypes, false);
            result = CommonNodeFactory.createFunctionCall(function, argNodes, functionType);
            // the callNode needs to be instrumentable so that the debugger can see the CallTag.
            // If it did not provide a source location, the debugger may not be able to show the
            // node on the call stack or offer stepping into the call.
            intent = SourceInstrumentationStrategy.FORCED;
        }
    }
    addStatement(result, call, intent);
}
Also used : FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) TypeArrayBuilder(com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMAssume(com.oracle.truffle.llvm.runtime.nodes.intrinsics.llvm.LLVMAssume) InlineAsmConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 3 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

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 LLVMParserException("\'extractvalue\' can only extract elements of arrays and structs!");
    }
    final LLVMExpressionNode baseAddress = resolveOptimized(extract.getAggregate());
    final Type baseType = extract.getAggregate().getType();
    final Collection<Long> targetIndices = extract.getIndices();
    final Type resultType = extract.getType();
    LLVMExpressionNode targetAddress = CommonNodeFactory.getTargetAddress(baseAddress, baseType, targetIndices, nodeFactory, dataLayout);
    LLVMExpressionNode result = nodeFactory.createExtractValue(resultType, targetAddress);
    createFrameWrite(result, extract);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) 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) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 4 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

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 TypeArrayBuilder argTypes = new TypeArrayBuilder(argumentCount);
    int argIndex = 0;
    argNodes[argIndex] = nodeFactory.createGetStackFromFrame();
    argTypes.set(argIndex, new PointerType(null));
    argIndex++;
    final SymbolImpl target = call.getCallTarget();
    if (call.getOperandBundle() != null) {
        throw new LLVMParserException("Unsupported operand bundle on invoke of " + target.toString());
    }
    if (targetType instanceof StructureType) {
        argTypes.set(argIndex, new PointerType(targetType));
        argNodes[argIndex] = nodeFactory.createGetUniqueStackSpace(targetType, uniquesRegion);
        argIndex++;
    }
    int realArgumentCount = call.getCallTarget().getType() instanceof FunctionType ? ((FunctionType) call.getCallTarget().getType()).getNumberOfArguments() : argumentCount;
    for (int i = call.getArgumentCount() - 1; i >= 0; i--) {
        argNodes[argIndex + i] = resolveOptimized(call.getArgument(i), i, target, call.getArguments());
        argTypes.set(argIndex + i, call.getArgument(i).getType());
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        boolean isVarArg = i >= realArgumentCount;
        if (isByValue(paramAttr)) {
            argNodes[argIndex + i] = capsuleAddressByValue(argNodes[argIndex + i], argTypes.get(argIndex + i), paramAttr);
        } else if (isVarArg && isArrayByValue(argTypes.get(argIndex + i), argNodes[argIndex + i])) {
            argNodes[argIndex + i] = capsuleArrayByValue(argNodes[argIndex + i], argTypes.get(argIndex + i));
        }
    }
    int regularIndex = call.normalSuccessor().getBlockIndex();
    int unwindIndex = call.unwindSuccessor().getBlockIndex();
    ArrayList<Phi> normalTo = new ArrayList<>();
    ArrayList<Phi> unwindTo = new ArrayList<>();
    if (blockPhis != null) {
        for (LLVMPhiManager.Phi phi : blockPhis) {
            if (call.normalSuccessor() == phi.getBlock()) {
                normalTo.add(phi);
            } else {
                unwindTo.add(phi);
            }
        }
    }
    LLVMStatementNode normalPhi = createPhiWriteNodes(normalTo);
    LLVMStatementNode unwindPhi = createPhiWriteNodes(unwindTo);
    // Builtins are not AST-inlined for Invokes, instead a generic LLVMDispatchNode is used.
    LLVMExpressionNode function = symbols.resolve(target);
    LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(CommonNodeFactory.createFrameWrite(targetType, null, symbols.findOrAddFrameSlot(call)), function, argNodes, new FunctionType(targetType, argTypes, false), regularIndex, unwindIndex, normalPhi, unwindPhi);
    setControlFlowNode(result, call, SourceInstrumentationStrategy.FORCED);
}
Also used : LLVMPhiManager(com.oracle.truffle.llvm.parser.LLVMPhiManager) LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) 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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) TypeArrayBuilder(com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 5 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLScanner method findMapping.

private static TruffleFile findMapping(Path canonicalBCPath, String pathMappings, LLVMContext context) {
    if (pathMappings.isEmpty()) {
        return null;
    }
    final String[] mappings = pathMappings.split(":");
    for (String mapping : mappings) {
        final String[] splittedMapping = mapping.split("=");
        if (splittedMapping.length != 2) {
            throw new LLVMParserException("Malformed path mapping for *.ll files: " + pathMappings);
        }
        final Path mappedBCFile = Paths.get(splittedMapping[0]).normalize().toAbsolutePath();
        if (mappedBCFile.equals(canonicalBCPath)) {
            final Path mappedLLFile = Paths.get(splittedMapping[1]).normalize().toAbsolutePath();
            return context.getEnv().getInternalTruffleFile(mappedLLFile.toUri());
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Aggregations

LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)32 Type (com.oracle.truffle.llvm.runtime.types.Type)12 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)9 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 ArrayList (java.util.ArrayList)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)5 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)5 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)4 TypeArrayBuilder (com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder)3 Matcher (java.util.regex.Matcher)3 CallTarget (com.oracle.truffle.api.CallTarget)2 TruffleFile (com.oracle.truffle.api.TruffleFile)2