Search in sources :

Example 6 with CodeTree

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

the class FlatNodeGenFactory method persistSpecializationClass.

private Collection<IfTriple> persistSpecializationClass(FrameState frameState, SpecializationData specialization) {
    if (!useSpecializationClass(specialization)) {
        return Collections.emptyList();
    }
    String localName = createSpecializationLocalName(specialization);
    LocalVariable var = frameState.get(localName);
    if (var == null) {
        // no specialization class initialized
        return Collections.emptyList();
    }
    String persistFrameState = createSpecializationClassPersisted(specialization);
    if (frameState.getBoolean(persistFrameState, false)) {
        // no specialization class initialized
        return Collections.emptyList();
    } else {
        frameState.setBoolean(persistFrameState, true);
    }
    CodeTree ref = var.createReference();
    CodeTreeBuilder builder = new CodeTreeBuilder(null);
    builder.startStatement();
    builder.string("this.", createSpecializationFieldName(specialization));
    builder.string(" = ");
    if (specializationClassIsNode(specialization)) {
        builder.startCall("super", "insert").tree(ref).end();
    } else {
        builder.tree(ref);
    }
    builder.end();
    return Arrays.asList(new IfTriple(builder.build(), null, null));
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 7 with CodeTree

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

the class FlatNodeGenFactory method createSpecialize.

private CodeTree createSpecialize(CodeTreeBuilder parent, FrameState frameState, SpecializationGroup group, SpecializationData specialization) {
    CodeTreeBuilder builder = parent.create();
    List<IfTriple> triples = new ArrayList<>();
    triples.addAll(initializeSpecializationClass(frameState, specialization));
    triples.addAll(initializeCaches(frameState, group, specialization.getCaches(), NodeExecutionMode.SLOW_PATH, false, true));
    triples.addAll(persistAssumptions(frameState, specialization));
    triples.addAll(persistSpecializationClass(frameState, specialization));
    builder.end(IfTriple.materialize(builder, triples, true));
    List<SpecializationData> excludesSpecializations = new ArrayList<>();
    for (SpecializationData otherSpeciailzation : reachableSpecializations) {
        if (otherSpeciailzation == specialization) {
            continue;
        }
        if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
            excludesSpecializations.add(otherSpeciailzation);
        }
    }
    if (!excludesSpecializations.isEmpty()) {
        SpecializationData[] excludesArray = excludesSpecializations.toArray(new SpecializationData[0]);
        builder.tree(exclude.createSet(frameState, excludesArray, true, true));
        for (SpecializationData excludes : excludesArray) {
            if (useSpecializationClass(excludes)) {
                builder.statement("this." + createSpecializationFieldName(excludes) + " = null");
            }
        }
        builder.tree((state.createSet(frameState, excludesArray, false, false)));
    }
    CodeTree updateImplicitCast = createUpdateImplicitCastState(builder, frameState, specialization);
    if (updateImplicitCast != null) {
        builder.tree(createUpdateImplicitCastState(builder, frameState, specialization));
    }
    builder.tree(state.createSet(frameState, new SpecializationData[] { specialization }, true, true));
    return builder.build();
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) ArrayList(java.util.ArrayList) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 8 with CodeTree

use of com.oracle.truffle.dsl.processor.java.model.CodeTree 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 9 with CodeTree

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

the class FlatNodeGenFactory method callTemplateMethod.

private CodeTree callTemplateMethod(CodeTree receiver, TemplateMethod method, FrameState frameState) {
    CodeTree[] bindings = new CodeTree[method.getParameters().size()];
    int signatureIndex = 0;
    for (int i = 0; i < bindings.length; i++) {
        Parameter parameter = method.getParameters().get(i);
        if (parameter.getSpecification().isCached() && method instanceof SpecializationData) {
            bindings[i] = createCacheReference(frameState, (SpecializationData) method, parameter);
        } else {
            LocalVariable var = frameState.get(parameter, signatureIndex);
            if (var == null) {
                var = frameState.get(parameter.getLocalName());
            }
            if (var != null) {
                bindings[i] = createParameterReference(var, method.getMethod(), i);
            }
        }
        if (parameter.getSpecification().isSignature()) {
            signatureIndex++;
        }
    }
    return callMethod(receiver, method.getMethod(), bindings);
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) Parameter(com.oracle.truffle.dsl.processor.model.Parameter)

Example 10 with CodeTree

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

the class FlatNodeGenFactory method combineTrees.

private static CodeTree combineTrees(String sep, CodeTree... trees) {
    CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
    String s = "";
    for (CodeTree tree : trees) {
        if (tree != null && !tree.isEmpty()) {
            if (sep != null) {
                builder.string(s);
            }
            builder.tree(tree);
            s = sep;
        }
    }
    return builder.build();
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Aggregations

CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)34 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)21 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)14 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)14 TypeMirror (javax.lang.model.type.TypeMirror)14 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)13 ArrayList (java.util.ArrayList)13 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)6 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)6 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)5 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)5 VariableElement (javax.lang.model.element.VariableElement)5 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)4 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)3 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)3 SpecializationGroup (com.oracle.truffle.dsl.processor.parser.SpecializationGroup)3 TypeGuard (com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)2 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)2