Search in sources :

Example 1 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project TrufflePascal by Aspect26.

the class ReadBuiltinNode method read.

@Specialization
public void read(Object[] arguments) {
    this.input = PascalLanguage.INSTANCE.findContext().getInput();
    if (arguments.length == 0) {
        readOne();
    }
    FileValue file = tryGetFileValue((Reference) arguments[0]);
    if (file != null) {
        read(file, Arrays.copyOfRange(arguments, 1, arguments.length));
    } else {
        read(null, arguments);
    }
}
Also used : FileValue(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.FileValue) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 2 with Specialization

use of com.oracle.truffle.api.dsl.Specialization 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 3 with Specialization

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

the class SlowPathSerializeArgumentNode method genericWithPrepare.

@Specialization(replaces = "cacheType", guards = { "value != null" })
protected Object genericWithPrepare(NativeArgumentBuffer buffer, LibFFIType type, TruffleObject value, @Cached("createUnbox()") Node unbox, @Cached("createIsExecutable()") Node isExecutable, @Cached("createAsPointer()") AsPointerNode asPointer, @Cached("createRecursive()") SlowPathSerializeArgumentNode recursive) {
    Object prepared = type.slowpathPrepareArgument(value);
    if (prepared == PrepareArgument.EXECUTABLE) {
        if (ForeignAccess.sendIsExecutable(isExecutable, value)) {
            prepared = value;
        } else {
            prepared = PrepareArgument.POINTER;
        }
    }
    if (prepared == PrepareArgument.POINTER) {
        prepared = asPointer.execute(value);
    } else if (prepared == PrepareArgument.UNBOX) {
        Object unboxed;
        try {
            unboxed = ForeignAccess.sendUnbox(unbox, value);
        } catch (UnsupportedMessageException ex) {
            throw UnsupportedTypeException.raise(ex, new Object[] { value });
        }
        return recursive.execute(buffer, type, unboxed);
    }
    slowPathSerialize(buffer, type, prepared);
    return null;
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 4 with Specialization

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

the class SLDefineFunctionBuiltin method defineFunction.

@TruffleBoundary
@Specialization
public String defineFunction(String code) {
    // @formatter:off
    Source source = Source.newBuilder(code).name("[defineFunction]").mimeType(SLLanguage.MIME_TYPE).build();
    // @formatter:on
    /* The same parsing code as for parsing the initial source. */
    getContext().getFunctionRegistry().register(source);
    return code;
}
Also used : Source(com.oracle.truffle.api.source.Source) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 5 with Specialization

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

the class SLHelloEqualsWorldBuiltin method change.

@Specialization
@TruffleBoundary
public String change() {
    FrameInstance frameInstance = Truffle.getRuntime().getCallerFrame();
    Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE);
    FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello");
    frame.setObject(slot, "world");
    return "world";
}
Also used : Frame(com.oracle.truffle.api.frame.Frame) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Specialization (com.oracle.truffle.api.dsl.Specialization)73 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)35 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)6 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)6 LLVMAddress (com.oracle.truffle.llvm.runtime.LLVMAddress)6 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 FileValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.FileValue)3 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)3 Frame (com.oracle.truffle.api.frame.Frame)2 InteropException (com.oracle.truffle.api.interop.InteropException)2 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Type (java.lang.reflect.Type)2 Assumption (com.oracle.truffle.api.Assumption)1