Search in sources :

Example 6 with CodeTreeBuilder

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

the class FlatNodeGenFactory method createMethodGuardCheck.

private List<IfTriple> createMethodGuardCheck(FrameState frameState, SpecializationGroup group, List<GuardExpression> guardExpressions, NodeExecutionMode mode) {
    List<IfTriple> triples = new ArrayList<>();
    for (GuardExpression guard : guardExpressions) {
        if (mode.isSlowPath() && !guard.isConstantTrueInSlowPath(context)) {
            CodeTreeBuilder builder = new CodeTreeBuilder(null);
            boolean guardStateBit = false;
            List<IfTriple> innerTriples = new ArrayList<>();
            if (guardNeedsStateBit(group.getSpecialization(), guard)) {
                if (group.getSpecialization() == null) {
                    throw new AssertionError();
                }
                builder.startIf().tree(state.createNotContains(frameState, new Object[] { guard })).end().startBlock();
                innerTriples.addAll(initializeSpecializationClass(frameState, group.getSpecialization()));
                innerTriples.addAll(persistSpecializationClass(frameState, group.getSpecialization()));
                guardStateBit = true;
            }
            innerTriples.addAll(initializeCaches(frameState, group, group.getSpecialization().getBoundCaches(guard.getExpression()), mode, !guardStateBit, guardStateBit));
            innerTriples.addAll(initializeCasts(frameState, group, guard.getExpression(), mode));
            IfTriple.materialize(builder, innerTriples, true);
            if (guardStateBit) {
                builder.tree(state.createSet(frameState, new Object[] { guard }, true, true));
                builder.end();
            }
            triples.add(new IfTriple(builder.build(), null, null));
        } else if (mode.isGuardFallback()) {
            triples.addAll(initializeCasts(frameState, group, guard.getExpression(), mode));
        }
        triples.add(createMethodGuardCheck(frameState, group.getSpecialization(), guard, mode));
    }
    return triples;
}
Also used : GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) ArrayList(java.util.ArrayList) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 7 with CodeTreeBuilder

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

the class FlatNodeGenFactory method createAssumptionCheckTriples.

private List<IfTriple> createAssumptionCheckTriples(FrameState frameState, SpecializationData specialization) {
    if (specialization == null || specialization.getAssumptionExpressions().isEmpty()) {
        return Collections.emptyList();
    }
    List<IfTriple> triples = new ArrayList<>();
    List<AssumptionExpression> assumptions = specialization.getAssumptionExpressions();
    for (AssumptionExpression assumption : assumptions) {
        CodeTree assumptionReference = createAssumptionReference(frameState, specialization, assumption);
        CodeTree assumptionGuard = createAssumptionGuard(assumption, assumptionReference);
        CodeTreeBuilder builder = new CodeTreeBuilder(null);
        builder.string("(");
        builder.tree(assumptionReference).string(" == null || ");
        builder.tree(assumptionGuard);
        builder.string(")");
        triples.add(new IfTriple(null, builder.build(), null));
    }
    return triples;
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) ArrayList(java.util.ArrayList) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression)

Example 8 with CodeTreeBuilder

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

the class FlatNodeGenFactory method createFastPathAssumptionCheck.

private CodeTree createFastPathAssumptionCheck(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData forType, FrameState frameState) throws AssertionError {
    CodeTreeBuilder builder = parent.create();
    builder.startIf();
    String sep = "";
    for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
        builder.string(sep);
        builder.string("!");
        builder.startCall("isValid_").tree(createAssumptionReference(frameState, specialization, assumption)).end();
        isValidSignatures.put(ElementUtils.getQualifiedName(assumption.getExpression().getResolvedType()), assumption.getExpression().getResolvedType());
        sep = " || ";
    }
    builder.end().startBlock();
    builder.tree(createTransferToInterpreterAndInvalidate());
    builder.tree(createRemoveThis(builder, frameState, forType, specialization));
    builder.end();
    return builder.build();
}
Also used : CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression)

Example 9 with CodeTreeBuilder

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

the class FlatNodeGenFactory method initializeSpecializationClass.

private Collection<? extends IfTriple> initializeSpecializationClass(FrameState frameState, SpecializationData specialization) {
    boolean useSpecializationClass = useSpecializationClass(specialization);
    if (useSpecializationClass) {
        String localName = createSpecializationLocalName(specialization);
        String typeName = createSpecializationTypeName(specialization);
        // we cannot use local name, because its used track reads not init writes
        String classInitialized = createSpecializationClassInitialized(specialization);
        if (!frameState.getBoolean(classInitialized, false)) {
            GeneratedTypeMirror type = new GeneratedTypeMirror("", typeName);
            CodeTreeBuilder initBuilder = new CodeTreeBuilder(null);
            initBuilder.startNew(typeName);
            if (specialization.getMaximumNumberOfInstances() > 1) {
                initBuilder.string(createSpecializationFieldName(specialization));
            }
            // new
            initBuilder.end();
            CodeTree init = initBuilder.build();
            CodeTreeBuilder builder = new CodeTreeBuilder(null);
            builder.startStatement();
            if (frameState.get(localName) == null) {
                // not yet declared
                builder.string(typeName);
                builder.string(" ");
            }
            builder.string(localName);
            builder.string(" = ");
            builder.tree(init);
            builder.end();
            frameState.setBoolean(classInitialized, true);
            frameState.set(localName, new LocalVariable(type, localName, CodeTreeBuilder.singleString(localName)));
            return Arrays.asList(new IfTriple(builder.build(), null, null));
        }
    }
    return Collections.emptyList();
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 10 with CodeTreeBuilder

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

the class FlatNodeGenFactory method createExecuteChild.

private ChildExecutionResult createExecuteChild(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
    ChildExecutionResult result;
    if (!typeSystem.hasImplicitSourceTypes(target.getTypeMirror())) {
        ExecutableTypeData targetExecutable = resolveTargetExecutable(execution, target.typeMirror);
        final CodeTreeBuilder builder = parent.create();
        result = createCallSingleChildExecute(execution, target, frameState, targetExecutable);
        builder.string(target.getName()).string(" = ");
        builder.tree(result.code);
        result.code = builder.build();
    } else {
        result = createExecuteChildImplicitCast(parent.create(), originalFrameState, frameState, execution, target);
    }
    return result;
}
Also used : ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Aggregations

CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)64 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)23 TypeMirror (javax.lang.model.type.TypeMirror)23 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)21 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)20 ArrayList (java.util.ArrayList)18 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)17 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)16 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)13 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)12 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)8 VariableElement (javax.lang.model.element.VariableElement)8 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)7 ExecutableElement (javax.lang.model.element.ExecutableElement)7 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)5 ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)5 Arrays (java.util.Arrays)5 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)4 AssumptionExpression (com.oracle.truffle.dsl.processor.model.AssumptionExpression)4 SpecializationGroup (com.oracle.truffle.dsl.processor.parser.SpecializationGroup)4