Search in sources :

Example 1 with Fallback

use of com.oracle.truffle.api.dsl.Fallback in project graal by oracle.

the class NodeParser method initializeFallbackReachability.

private static void initializeFallbackReachability(NodeData node) {
    List<SpecializationData> specializations = node.getSpecializations();
    SpecializationData fallback = null;
    for (int i = specializations.size() - 1; i >= 0; i--) {
        SpecializationData specialization = specializations.get(i);
        if (specialization.isFallback() && specialization.getMethod() != null) {
            fallback = specialization;
            break;
        }
    }
    if (fallback == null) {
        // no need to compute reachability
        return;
    }
    for (int index = 0; index < specializations.size(); index++) {
        SpecializationData specialization = specializations.get(index);
        SpecializationData lastReachable = specialization;
        for (int searchIndex = index + 1; searchIndex < specializations.size(); searchIndex++) {
            SpecializationData search = specializations.get(searchIndex);
            if (search == fallback) {
                // reached the end of the specialization
                break;
            }
            assert lastReachable != search;
            if (!lastReachable.isReachableAfter(search)) {
                lastReachable = search;
            } else if (search.getReplaces().contains(specialization)) {
                lastReachable = search;
            }
        }
        specialization.setReachesFallback(lastReachable == specialization);
        List<SpecializationData> failedSpecializations = null;
        if (specialization.isReachesFallback() && !specialization.getCaches().isEmpty() && !specialization.getGuards().isEmpty()) {
            boolean guardBoundByCache = false;
            for (GuardExpression guard : specialization.getGuards()) {
                if (specialization.isGuardBoundWithCache(guard)) {
                    guardBoundByCache = true;
                    break;
                }
            }
            if (guardBoundByCache && specialization.getMaximumNumberOfInstances() > 1) {
                if (failedSpecializations == null) {
                    failedSpecializations = new ArrayList<>();
                }
                failedSpecializations.add(specialization);
            }
        }
        if (failedSpecializations != null) {
            List<String> specializationIds = failedSpecializations.stream().map((e) -> e.getId()).collect(Collectors.toList());
            fallback.addError("Some guards for the following specializations could not be negated for the @%s specialization: %s. " + "Guards cannot be negated for the @%s when they bind @%s parameters and the specialization may consist of multiple instances. " + "To fix this limit the number of instances to '1' or " + "introduce a more generic specialization declared between this specialization and the fallback. " + "Alternatively the use of @%s can be avoided by declaring a @%s with manually specified negated guards.", Fallback.class.getSimpleName(), specializationIds, Fallback.class.getSimpleName(), Cached.class.getSimpleName(), Fallback.class.getSimpleName(), Specialization.class.getSimpleName());
        }
    }
}
Also used : Arrays(java.util.Arrays) Children(com.oracle.truffle.api.nodes.Node.Children) ListIterator(java.util.ListIterator) Modifier(javax.lang.model.element.Modifier) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) Specialization(com.oracle.truffle.api.dsl.Specialization) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression) MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec) TypeElement(javax.lang.model.element.TypeElement) NodeInterface(com.oracle.truffle.api.nodes.NodeInterface) Executed(com.oracle.truffle.api.dsl.Executed) NodeFieldData(com.oracle.truffle.dsl.processor.model.NodeFieldData) NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) NodeField(com.oracle.truffle.api.dsl.NodeField) Map(java.util.Map) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) Log(com.oracle.truffle.dsl.processor.Log) ArrayType(javax.lang.model.type.ArrayType) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) GenerateNodeFactory(com.oracle.truffle.api.dsl.GenerateNodeFactory) Collection(java.util.Collection) Set(java.util.Set) Element(javax.lang.model.element.Element) Collectors(java.util.stream.Collectors) TypeKind(javax.lang.model.type.TypeKind) Objects(java.util.Objects) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) List(java.util.List) CreateCast(com.oracle.truffle.api.dsl.CreateCast) TemplateMethod(com.oracle.truffle.dsl.processor.model.TemplateMethod) ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec) NodeChildData(com.oracle.truffle.dsl.processor.model.NodeChildData) Annotation(java.lang.annotation.Annotation) Cardinality(com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality) AnnotationValue(javax.lang.model.element.AnnotationValue) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) Cached(com.oracle.truffle.api.dsl.Cached) Child(com.oracle.truffle.api.nodes.Node.Child) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) TypeSystemData(com.oracle.truffle.dsl.processor.model.TypeSystemData) VariableElement(javax.lang.model.element.VariableElement) Fallback(com.oracle.truffle.api.dsl.Fallback) GeneratedBy(com.oracle.truffle.api.dsl.GeneratedBy) SpecializationKind(com.oracle.truffle.dsl.processor.model.SpecializationData.SpecializationKind) HashMap(java.util.HashMap) NodeFields(com.oracle.truffle.api.dsl.NodeFields) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Kind(javax.tools.Diagnostic.Kind) CompilerFactory(com.oracle.truffle.dsl.processor.java.compiler.CompilerFactory) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) SpecializationThrowsData(com.oracle.truffle.dsl.processor.model.SpecializationThrowsData) DeclaredType(javax.lang.model.type.DeclaredType) InvalidExpressionException(com.oracle.truffle.dsl.processor.expression.InvalidExpressionException) ElementFilter(javax.lang.model.util.ElementFilter) ImportStatic(com.oracle.truffle.api.dsl.ImportStatic) ElementUtils(com.oracle.truffle.dsl.processor.java.ElementUtils) NodeChildren(com.oracle.truffle.api.dsl.NodeChildren) Iterator(java.util.Iterator) ElementKind(javax.lang.model.element.ElementKind) TypeSystemReference(com.oracle.truffle.api.dsl.TypeSystemReference) CompileErrorException(com.oracle.truffle.dsl.processor.CompileErrorException) ExecutableElement(javax.lang.model.element.ExecutableElement) NodeChild(com.oracle.truffle.api.dsl.NodeChild) Assumption(com.oracle.truffle.api.Assumption) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) Frame(com.oracle.truffle.api.frame.Frame) Comparator(java.util.Comparator) ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) Collections(java.util.Collections) Introspectable(com.oracle.truffle.api.dsl.Introspectable) ReportPolymorphism(com.oracle.truffle.api.dsl.ReportPolymorphism) DSLExpressionResolver(com.oracle.truffle.dsl.processor.expression.DSLExpressionResolver) Specialization(com.oracle.truffle.api.dsl.Specialization) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) Fallback(com.oracle.truffle.api.dsl.Fallback) Cached(com.oracle.truffle.api.dsl.Cached)

Example 2 with Fallback

use of com.oracle.truffle.api.dsl.Fallback in project sulong by graalvm.

the class LLVMInteropWriteNode method doUnknownType.

@Fallback
void doUnknownType(@SuppressWarnings("unused") LLVMInteropType.Structured type, TruffleObject foreign, long offset, Object value) {
    if (getSize == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        getSize = insert(GetValueSizeNodeGen.create());
    }
    // type unknown: fall back to "array of unknown value type"
    int elementAccessSize = getSize.execute(value);
    AccessLocation location = new AccessLocation(foreign, Long.divideUnsigned(offset, elementAccessSize), null);
    write(location, value);
}
Also used : AccessLocation(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropAccessNode.AccessLocation) Fallback(com.oracle.truffle.api.dsl.Fallback)

Aggregations

Fallback (com.oracle.truffle.api.dsl.Fallback)2 Assumption (com.oracle.truffle.api.Assumption)1 Cached (com.oracle.truffle.api.dsl.Cached)1 CreateCast (com.oracle.truffle.api.dsl.CreateCast)1 Executed (com.oracle.truffle.api.dsl.Executed)1 GenerateNodeFactory (com.oracle.truffle.api.dsl.GenerateNodeFactory)1 GeneratedBy (com.oracle.truffle.api.dsl.GeneratedBy)1 ImportStatic (com.oracle.truffle.api.dsl.ImportStatic)1 Introspectable (com.oracle.truffle.api.dsl.Introspectable)1 NodeChild (com.oracle.truffle.api.dsl.NodeChild)1 NodeChildren (com.oracle.truffle.api.dsl.NodeChildren)1 NodeField (com.oracle.truffle.api.dsl.NodeField)1 NodeFields (com.oracle.truffle.api.dsl.NodeFields)1 ReportPolymorphism (com.oracle.truffle.api.dsl.ReportPolymorphism)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 TypeSystemReference (com.oracle.truffle.api.dsl.TypeSystemReference)1 Frame (com.oracle.truffle.api.frame.Frame)1 Child (com.oracle.truffle.api.nodes.Node.Child)1 Children (com.oracle.truffle.api.nodes.Node.Children)1 NodeInterface (com.oracle.truffle.api.nodes.NodeInterface)1