Search in sources :

Example 1 with ExecutableTypeData

use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.

the class FlatNodeGenFactory method resolveOptimizedImplicitSourceTypes.

private List<TypeMirror> resolveOptimizedImplicitSourceTypes(NodeExecutionData execution, TypeMirror targetType) {
    List<TypeMirror> allSourceTypes = typeSystem.lookupSourceTypes(targetType);
    List<TypeMirror> filteredSourceTypes = new ArrayList<>();
    for (TypeMirror sourceType : allSourceTypes) {
        ExecutableTypeData executableType = resolveTargetExecutable(execution, sourceType);
        if (executableType == null) {
            continue;
        }
        if (!ElementUtils.isPrimitive(sourceType) || !boxingEliminationEnabled) {
            // don't optimize non primitives
            continue;
        }
        if (!ElementUtils.typeEquals(executableType.getReturnType(), sourceType)) {
            // no boxing optimization possible
            continue;
        }
        filteredSourceTypes.add(sourceType);
    }
    return filteredSourceTypes;
}
Also used : ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ArrayList(java.util.ArrayList)

Example 2 with ExecutableTypeData

use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.

the class FlatNodeGenFactory method createExecuteChild.

private ChildExecutionResult createExecuteChild(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
    ChildExecutionResult result;
    if (!typeSystem.hasImplicitSourceTypes(target.getTypeMirror())) {
        ExecutableTypeData targetExecutable = resolveTargetExecutable(execution, target.typeMirror);
        final CodeTreeBuilder builder = parent.create();
        result = createCallSingleChildExecute(execution, target, frameState, targetExecutable);
        builder.string(target.getName()).string(" = ");
        builder.tree(result.code);
        result.code = builder.build();
    } else {
        result = createExecuteChildImplicitCast(parent.create(), originalFrameState, frameState, execution, target);
    }
    return result;
}
Also used : ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 3 with ExecutableTypeData

use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.

the class FlatNodeGenFactory method createAssignExecuteChild.

private CodeTree createAssignExecuteChild(FrameState originalFrameState, FrameState frameState, CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData forType, LocalVariable targetValue) {
    CodeTreeBuilder builder = parent.create();
    ChildExecutionResult executeChild = createExecuteChild(builder, originalFrameState, frameState, execution, targetValue);
    builder.tree(createTryExecuteChild(targetValue, executeChild.code, true, executeChild.throwsUnexpectedResult));
    builder.end();
    if (executeChild.throwsUnexpectedResult) {
        builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
        FrameState slowPathFrameState = originalFrameState.copy();
        slowPathFrameState.setValue(execution, targetValue.makeGeneric(context).accessWith(CodeTreeBuilder.singleString("ex.getResult()")));
        ExecutableTypeData delegateType = node.getGenericExecutableType(forType);
        boolean found = false;
        for (NodeExecutionData otherExecution : node.getChildExecutions()) {
            if (found) {
                LocalVariable childEvaluatedValue = slowPathFrameState.createValue(otherExecution, genericType);
                builder.tree(createAssignExecuteChild(slowPathFrameState.copy(), slowPathFrameState, builder, otherExecution, delegateType, childEvaluatedValue));
                slowPathFrameState.setValue(otherExecution, childEvaluatedValue);
            } else {
                // skip forward already evaluated
                found = execution == otherExecution;
            }
        }
        builder.tree(createCallExecuteAndSpecialize(forType, slowPathFrameState));
        builder.end();
    }
    return builder.build();
}
Also used : ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 4 with ExecutableTypeData

use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.

the class FlatNodeGenFactory method createExecuteChildImplicitCast.

private ChildExecutionResult createExecuteChildImplicitCast(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
    CodeTreeBuilder builder = parent.create();
    List<TypeMirror> originalSourceTypes = typeSystem.lookupSourceTypes(target.getTypeMirror());
    List<TypeMirror> sourceTypes = resolveOptimizedImplicitSourceTypes(execution, target.getTypeMirror());
    TypeGuard typeGuard = new TypeGuard(target.getTypeMirror(), execution.getIndex());
    boolean throwsUnexpected = false;
    boolean elseIf = false;
    for (TypeMirror sourceType : sourceTypes) {
        ExecutableTypeData executableType = resolveTargetExecutable(execution, sourceType);
        elseIf = builder.startIf(elseIf);
        throwsUnexpected |= executableType.hasUnexpectedValue(context);
        builder.startGroup();
        builder.tree(state.createContainsOnly(frameState, originalSourceTypes.indexOf(sourceType), 1, new Object[] { typeGuard }, new Object[] { typeGuard }));
        builder.string(" && ");
        builder.tree(state.createIsNotAny(frameState, reachableSpecializationsArray));
        builder.end();
        builder.end();
        builder.startBlock();
        CodeTree value = callChildExecuteMethod(execution, executableType, frameState);
        value = expect(executableType.getReturnType(), sourceType, value);
        throwsUnexpected |= needsCastTo(executableType.getReturnType(), sourceType);
        ImplicitCastData cast = typeSystem.lookupCast(sourceType, target.getTypeMirror());
        if (cast != null) {
            // we need to store the original value to restore it in
            // case of a deopt
            String localName = createSourceTypeLocalName(target, sourceType);
            builder.startStatement().string(localName).string(" = ").tree(value).end();
            value = callMethod(null, cast.getMethod(), CodeTreeBuilder.singleString(localName));
        }
        builder.startStatement().string(target.getName()).string(" = ").tree(value).end();
        builder.end();
    }
    if (elseIf) {
        builder.startElseBlock();
    }
    LocalVariable genericValue = target.makeGeneric(context).nextName();
    builder.tree(createAssignExecuteChild(originalFrameState, frameState, builder, execution, node.getGenericExecutableType(null), genericValue));
    builder.startStatement().string(target.getName()).string(" = ");
    CodeTree implicitState = state.createExtractInteger(frameState, typeGuard);
    builder.tree(TypeSystemCodeGenerator.implicitExpectFlat(typeSystem, target.getTypeMirror(), genericValue.createReference(), implicitState));
    builder.end();
    if (!sourceTypes.isEmpty()) {
        builder.end();
    }
    return new ChildExecutionResult(builder.build(), throwsUnexpected);
}
Also used : ImplicitCastData(com.oracle.truffle.dsl.processor.model.ImplicitCastData) ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) TypeGuard(com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)

Example 5 with ExecutableTypeData

use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.

the class NodeParser method initializeExecutableTypeHierarchy.

private static void initializeExecutableTypeHierarchy(NodeData node) {
    SpecializationData polymorphic = node.getPolymorphicSpecialization();
    if (polymorphic != null) {
        boolean polymorphicSignatureFound = false;
        List<TypeMirror> dynamicTypes = polymorphic.getDynamicTypes();
        TypeMirror frame = null;
        if (polymorphic.getFrame() != null) {
            frame = dynamicTypes.remove(0);
        }
        ExecutableTypeData polymorphicType = new ExecutableTypeData(node, polymorphic.getReturnType().getType(), "execute", frame, dynamicTypes);
        String genericName = ExecutableTypeData.createName(polymorphicType) + "_";
        polymorphicType.setUniqueName(genericName);
        for (ExecutableTypeData type : node.getExecutableTypes()) {
            if (polymorphicType.sameSignature(type)) {
                polymorphicSignatureFound = true;
                break;
            }
        }
        if (!polymorphicSignatureFound) {
            node.getExecutableTypes().add(polymorphicType);
        }
    }
    List<ExecutableTypeData> rootTypes = buildExecutableHierarchy(node);
    List<ExecutableTypeData> additionalAbstractRootTypes = new ArrayList<>();
    for (int i = 1; i < rootTypes.size(); i++) {
        ExecutableTypeData rootType = rootTypes.get(i);
        if (rootType.isAbstract()) {
            // cannot implemement root
            additionalAbstractRootTypes.add(rootType);
        } else {
            node.getExecutableTypes().remove(rootType);
        }
    }
    if (!additionalAbstractRootTypes.isEmpty()) {
        node.addError("Incompatible abstract execute methods found %s.", additionalAbstractRootTypes);
    }
    namesUnique(node.getExecutableTypes());
}
Also used : ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) ArrayList(java.util.ArrayList)

Aggregations

ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)16 ArrayList (java.util.ArrayList)11 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)10 TypeMirror (javax.lang.model.type.TypeMirror)10 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)6 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)6 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)6 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)5 NodeChildData (com.oracle.truffle.dsl.processor.model.NodeChildData)4 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)4 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)3 HashSet (java.util.HashSet)3 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)2 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)2 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)2 LinkedHashSet (java.util.LinkedHashSet)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1 Child (com.oracle.truffle.api.nodes.Node.Child)1 NodeInfo (com.oracle.truffle.api.nodes.NodeInfo)1