Search in sources :

Example 16 with SpecializationData

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

the class NodeParser method resolveReplaces.

private void resolveReplaces(NodeData node) {
    // flatten transitive includes
    for (SpecializationData specialization : node.getSpecializations()) {
        if (specialization.getReplaces().isEmpty()) {
            continue;
        }
        Set<SpecializationData> foundSpecializations = new HashSet<>();
        collectIncludes(specialization, foundSpecializations, new HashSet<SpecializationData>());
        specialization.getReplaces().addAll(foundSpecializations);
    }
}
Also used : SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) HashSet(java.util.HashSet)

Example 17 with SpecializationData

use of com.oracle.truffle.dsl.processor.model.SpecializationData 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)

Example 18 with SpecializationData

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

the class NodeParser method initializeReachability.

private static void initializeReachability(final NodeData node) {
    List<SpecializationData> specializations = node.getSpecializations();
    for (int i = specializations.size() - 1; i >= 0; i--) {
        SpecializationData current = specializations.get(i);
        if (current.isPolymorphic()) {
            current.setReachable(true);
            continue;
        }
        List<SpecializationData> shadowedBy = null;
        for (int j = i - 1; j >= 0; j--) {
            SpecializationData prev = specializations.get(j);
            if (prev.isPolymorphic()) {
                continue;
            }
            if (!current.isReachableAfter(prev)) {
                if (shadowedBy == null) {
                    shadowedBy = new ArrayList<>();
                }
                shadowedBy.add(prev);
            }
        }
        if (shadowedBy != null) {
            StringBuilder name = new StringBuilder();
            String sep = "";
            for (SpecializationData shadowSpecialization : shadowedBy) {
                name.append(sep);
                name.append(shadowSpecialization.createReferenceName());
                sep = ", ";
            }
            current.addError("%s is not reachable. It is shadowed by %s.", current.isFallback() ? "Generic" : "Specialization", name);
        }
        current.setReachable(shadowedBy == null);
    }
}
Also used : SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData)

Example 19 with SpecializationData

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

the class NodeParser method initializeOrder.

private static void initializeOrder(NodeData node) {
    List<SpecializationData> specializations = node.getSpecializations();
    Collections.sort(specializations);
    for (SpecializationData specialization : specializations) {
        String searchName = specialization.getInsertBeforeName();
        if (searchName == null || specialization.getMethod() == null) {
            continue;
        }
        SpecializationData found = lookupSpecialization(node, searchName);
        if (found == null || found.getMethod() == null) {
            AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
            specialization.addError(value, "The referenced specialization '%s' could not be found.", searchName);
            continue;
        }
        ExecutableElement currentMethod = specialization.getMethod();
        ExecutableElement insertBeforeMethod = found.getMethod();
        TypeMirror currentEnclosedType = currentMethod.getEnclosingElement().asType();
        TypeMirror insertBeforeEnclosedType = insertBeforeMethod.getEnclosingElement().asType();
        if (ElementUtils.typeEquals(currentEnclosedType, insertBeforeEnclosedType) || !ElementUtils.isSubtype(currentEnclosedType, insertBeforeEnclosedType)) {
            AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
            specialization.addError(value, "Specializations can only be inserted before specializations in superclasses.", searchName);
            continue;
        }
        specialization.setInsertBefore(found);
    }
    for (int i = 0; i < specializations.size(); i++) {
        SpecializationData specialization = specializations.get(i);
        SpecializationData insertBefore = specialization.getInsertBefore();
        if (insertBefore != null) {
            int insertIndex = specializations.indexOf(insertBefore);
            if (insertIndex < i) {
                specializations.remove(i);
                specializations.add(insertIndex, specialization);
            }
        }
    }
    for (int i = 0; i < specializations.size(); i++) {
        specializations.get(i).setIndex(i);
    }
}
Also used : ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 20 with SpecializationData

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

the class NodeParser method initializeSpecializations.

private void initializeSpecializations(List<? extends Element> elements, final NodeData node) {
    if (node.getSpecializations().isEmpty()) {
        return;
    }
    initializeExpressions(elements, node);
    if (node.hasErrors()) {
        return;
    }
    initializeGeneric(node);
    initializeUninitialized(node);
    initializeOrder(node);
    // requires specializations
    initializePolymorphism(node);
    initializeReachability(node);
    initializeReplaces(node);
    initializeFallbackReachability(node);
    resolveReplaces(node);
    List<SpecializationData> specializations = node.getSpecializations();
    for (SpecializationData cur : specializations) {
        for (SpecializationData contained : cur.getReplaces()) {
            if (contained != cur) {
                contained.getExcludedBy().add(cur);
            }
        }
    }
    initializeSpecializationIdsWithMethodNames(node.getSpecializations());
}
Also used : SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData)

Aggregations

SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)35 ArrayList (java.util.ArrayList)22 TypeMirror (javax.lang.model.type.TypeMirror)17 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)16 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)12 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)11 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)11 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)11 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)9 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)8 ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)7 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)6 HashSet (java.util.HashSet)6 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)5 VariableElement (javax.lang.model.element.VariableElement)5 AnnotationValue (javax.lang.model.element.AnnotationValue)4 ExecutableElement (javax.lang.model.element.ExecutableElement)4 Child (com.oracle.truffle.api.nodes.Node.Child)3 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)3 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)3