Search in sources :

Example 1 with NodeExecutionData

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

the class FlatNodeGenFactory method createThrowUnsupported.

private CodeTree createThrowUnsupported(final CodeTreeBuilder parent, final FrameState frameState) {
    CodeTreeBuilder builder = parent.create();
    builder.startThrow().startNew(context.getType(UnsupportedSpecializationException.class));
    builder.string("this");
    builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Node.class)), null);
    List<CodeTree> values = new ArrayList<>();
    for (NodeExecutionData execution : node.getChildExecutions()) {
        NodeChildData child = execution.getChild();
        LocalVariable var = frameState.getValue(execution);
        if (child != null) {
            builder.string(accessNodeField(execution));
        } else {
            builder.string("null");
        }
        if (var != null) {
            values.add(var.createReference());
        }
    }
    builder.end();
    builder.trees(values.toArray(new CodeTree[0]));
    builder.end().end();
    return builder.build();
}
Also used : NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) NodeChildData(com.oracle.truffle.dsl.processor.model.NodeChildData) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) UnsupportedSpecializationException(com.oracle.truffle.api.dsl.UnsupportedSpecializationException) ArrayList(java.util.ArrayList) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)

Example 2 with NodeExecutionData

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

the class FlatNodeGenFactory method bindExecuteMethodParameters.

private CodeTree[] bindExecuteMethodParameters(NodeExecutionData execution, ExecutableTypeData method, FrameState frameState) {
    List<NodeExecutionData> executeWith = execution != null ? execution.getChild().getExecuteWith() : null;
    List<CodeTree> values = new ArrayList<>();
    if (method.getFrameParameter() != null) {
        LocalVariable frameLocal = frameState.get(FRAME_VALUE);
        if (frameLocal == null) {
            values.add(CodeTreeBuilder.singleString("null"));
        } else {
            values.add(createParameterReference(frameLocal, method.getMethod(), 0));
        }
    }
    int evaluatedIndex = 0;
    for (int executionIndex = 0; executionIndex < node.getExecutionCount(); executionIndex++) {
        NodeExecutionData parameterExecution;
        if (executeWith != null && executionIndex < executeWith.size()) {
            parameterExecution = executeWith.get(executionIndex);
        } else {
            parameterExecution = node.getChildExecutions().get(executionIndex);
        }
        if (evaluatedIndex < method.getEvaluatedCount()) {
            TypeMirror targetType = method.getEvaluatedParameters().get(evaluatedIndex);
            LocalVariable value = frameState.getValue(parameterExecution);
            if (value != null) {
                int parameterIndex = method.getParameterIndex(evaluatedIndex);
                values.add(createParameterReference(value, method.getMethod(), parameterIndex));
            } else {
                values.add(CodeTreeBuilder.createBuilder().defaultValue(targetType).build());
            }
            evaluatedIndex++;
        }
    }
    return values.toArray(new CodeTree[values.size()]);
}
Also used : NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) 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 3 with NodeExecutionData

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

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

the class FlatNodeGenFactory method bindExpressionValues.

private Map<Variable, LocalVariable> bindExpressionValues(FrameState frameState, DSLExpression expression, SpecializationData specialization) throws AssertionError {
    Map<Variable, LocalVariable> bindings = new HashMap<>();
    Set<Variable> boundVariables = expression.findBoundVariables();
    if (specialization == null && !boundVariables.isEmpty()) {
        throw new AssertionError("Cannot bind guard variable in non-specialization group. yet.");
    }
    // resolve bindings for local context
    for (Variable variable : boundVariables) {
        Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable());
        if (resolvedParameter != null) {
            LocalVariable localVariable;
            if (resolvedParameter.getSpecification().isCached()) {
                // bind cached variable
                String cachedMemberName = createFieldName(specialization, resolvedParameter);
                localVariable = frameState.get(cachedMemberName);
                CodeTree ref;
                if (localVariable == null) {
                    ref = createCacheReference(frameState, specialization, resolvedParameter);
                } else {
                    ref = localVariable.createReference();
                }
                bindings.put(variable, new LocalVariable(resolvedParameter.getType(), cachedMemberName, ref));
            } else {
                // bind local variable
                if (resolvedParameter.getSpecification().isSignature()) {
                    NodeExecutionData execution = resolvedParameter.getSpecification().getExecution();
                    localVariable = frameState.getValue(execution);
                } else {
                    localVariable = frameState.get(resolvedParameter.getLocalName());
                }
                if (localVariable != null) {
                    bindings.put(variable, localVariable);
                }
            }
        }
    }
    return bindings;
}
Also used : Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) HashMap(java.util.HashMap) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) Parameter(com.oracle.truffle.dsl.processor.model.Parameter)

Example 5 with NodeExecutionData

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

the class FlatNodeGenFactory method createFastPath.

private CodeTree createFastPath(CodeTreeBuilder parent, List<SpecializationData> allSpecializations, SpecializationGroup originalGroup, final ExecutableTypeData currentType, FrameState frameState) {
    final CodeTreeBuilder builder = parent.create();
    builder.tree(state.createLoad(frameState));
    int sharedExecutes = 0;
    for (NodeExecutionData execution : node.getChildExecutions()) {
        boolean canExecuteChild = execution.getIndex() < currentType.getEvaluatedCount();
        for (TypeGuard checkedGuard : originalGroup.getTypeGuards()) {
            if (checkedGuard.getSignatureIndex() == execution.getIndex()) {
                canExecuteChild = true;
                break;
            }
        }
        if (!canExecuteChild) {
            break;
        }
        for (TypeGuard checkedGuard : originalGroup.getTypeGuards()) {
            // we cannot pull out guards that use optimized implicit source types
            if (resolveOptimizedImplicitSourceTypes(execution, checkedGuard.getType()).size() > 1) {
                canExecuteChild = false;
                break;
            }
        }
        if (!canExecuteChild) {
            break;
        }
        builder.tree(createFastPathExecuteChild(builder, frameState.copy(), frameState, currentType, originalGroup, execution));
        sharedExecutes++;
    }
    List<BoxingSplit> boxingSplits = parameterBoxingElimination(originalGroup, sharedExecutes);
    if (boxingSplits.isEmpty()) {
        builder.tree(executeFastPathGroup(builder, frameState, currentType, originalGroup, sharedExecutes, null));
        addExplodeLoop(builder, originalGroup);
    } else {
        FrameState originalFrameState = frameState.copy();
        boolean elseIf = false;
        for (BoxingSplit split : boxingSplits) {
            elseIf = builder.startIf(elseIf);
            List<SpecializationData> specializations = split.group.collectSpecializations();
            builder.startGroup();
            builder.tree(state.createContainsOnly(frameState, 0, -1, specializations.toArray(), allSpecializations.toArray())).end();
            builder.string(" && ");
            builder.tree(state.createIsNotAny(frameState, allSpecializations.toArray()));
            builder.end();
            builder.end().startBlock();
            builder.tree(wrapInAMethod(builder, split.group, originalFrameState, split.getName(), executeFastPathGroup(builder, frameState.copy(), currentType, split.group, sharedExecutes, specializations)));
            builder.end();
        }
        builder.startElseBlock();
        builder.tree(wrapInAMethod(builder, originalGroup, originalFrameState, "generic", executeFastPathGroup(builder, frameState, currentType, originalGroup, sharedExecutes, null)));
        builder.end();
    }
    return builder.build();
}
Also used : NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) TypeGuard(com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)

Aggregations

NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)18 ArrayList (java.util.ArrayList)11 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)10 TypeMirror (javax.lang.model.type.TypeMirror)10 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)8 NodeChildData (com.oracle.truffle.dsl.processor.model.NodeChildData)6 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)5 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)5 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)5 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)4 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)4 ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)4 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)4 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 VariableElement (javax.lang.model.element.VariableElement)3 NodeFieldData (com.oracle.truffle.dsl.processor.model.NodeFieldData)2 TypeGuard (com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)2 HashSet (java.util.HashSet)2 UnsupportedSpecializationException (com.oracle.truffle.api.dsl.UnsupportedSpecializationException)1