Search in sources :

Example 1 with Parameter

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

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

the class FlatNodeGenFactory method createUpdateImplicitCastState.

private CodeTree createUpdateImplicitCastState(CodeTreeBuilder parent, FrameState frameState, SpecializationData specialization) {
    CodeTreeBuilder builder = null;
    int signatureIndex = 0;
    for (Parameter p : specialization.getSignatureParameters()) {
        TypeMirror targetType = p.getType();
        TypeMirror polymorphicType = node.getPolymorphicSpecialization().findParameterOrDie(p.getSpecification().getExecution()).getType();
        if (typeSystem.hasImplicitSourceTypes(targetType) && needsCastTo(polymorphicType, targetType)) {
            String implicitFieldName = createImplicitTypeStateLocalName(p);
            if (builder == null) {
                builder = parent.create();
            }
            builder.tree(state.createSetInteger(frameState, new TypeGuard(p.getType(), signatureIndex), CodeTreeBuilder.singleString(implicitFieldName)));
        }
        signatureIndex++;
    }
    return builder == null ? null : builder.build();
}
Also used : 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) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) TypeGuard(com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)

Example 3 with Parameter

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

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

the class FlatNodeGenFactory method createFields.

private void createFields(CodeTypeElement clazz) {
    state.declareFields(clazz);
    if (requiresExclude()) {
        exclude.declareFields(clazz);
    }
    for (SpecializationData specialization : reachableSpecializations) {
        List<CodeVariableElement> fields = new ArrayList<>();
        boolean useSpecializationClass = useSpecializationClass(specialization);
        for (CacheExpression cache : specialization.getCaches()) {
            Parameter parameter = cache.getParameter();
            String fieldName = createFieldName(specialization, parameter);
            TypeMirror type = parameter.getType();
            Modifier visibility = useSpecializationClass ? null : Modifier.PRIVATE;
            CodeVariableElement cachedField;
            if (ElementUtils.isAssignable(type, context.getType(NodeInterface.class))) {
                cachedField = createNodeField(visibility, type, fieldName, Child.class);
            } else if (isNodeInterfaceArray(type)) {
                cachedField = createNodeField(visibility, type, fieldName, Children.class);
            } else {
                cachedField = createNodeField(visibility, type, fieldName, null);
                setFieldCompilationFinal(cachedField, parameter.getVariableElement().getAnnotation(Cached.class).dimensions());
            }
            fields.add(cachedField);
        }
        for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
            String fieldName = createAssumptionFieldName(specialization, assumption);
            TypeMirror type;
            int compilationFinalDimensions;
            if (assumption.getExpression().getResolvedType().getKind() == TypeKind.ARRAY) {
                type = context.getType(Assumption[].class);
                compilationFinalDimensions = 1;
            } else {
                type = context.getType(Assumption.class);
                compilationFinalDimensions = -1;
            }
            CodeVariableElement assumptionField;
            if (useSpecializationClass) {
                assumptionField = createNodeField(null, type, fieldName, null);
            } else {
                assumptionField = createNodeField(PRIVATE, type, fieldName, null);
            }
            setFieldCompilationFinal(assumptionField, compilationFinalDimensions);
            fields.add(assumptionField);
        }
        if (useSpecializationClass) {
            TypeMirror baseType;
            boolean useNode = specializationClassIsNode(specialization);
            if (useNode) {
                baseType = context.getType(Node.class);
            } else {
                baseType = context.getType(Object.class);
            }
            CodeTypeElement cacheType = GeneratorUtils.createClass(node, null, modifiers(PRIVATE, FINAL, STATIC), createSpecializationTypeName(specialization), baseType);
            Class<?> annotationType;
            if (useNode) {
                annotationType = Child.class;
                if (specialization.getMaximumNumberOfInstances() > 1) {
                    cacheType.add(createNodeField(null, cacheType.asType(), "next_", Child.class));
                }
                CodeExecutableElement getNodeCost = new CodeExecutableElement(modifiers(PUBLIC), context.getType(NodeCost.class), "getCost");
                getNodeCost.createBuilder().startReturn().staticReference(context.getType(NodeCost.class), "NONE").end();
                cacheType.add(getNodeCost);
            } else {
                annotationType = CompilationFinal.class;
                if (specialization.getMaximumNumberOfInstances() > 1) {
                    cacheType.add(createNodeField(null, cacheType.asType(), "next_", annotationType));
                }
            }
            cacheType.add(GeneratorUtils.createConstructorUsingFields(modifiers(), cacheType));
            cacheType.getEnclosedElements().addAll(fields);
            clazz.add(createNodeField(PRIVATE, cacheType.asType(), createSpecializationFieldName(specialization), annotationType));
            clazz.add(cacheType);
            specializationClasses.put(specialization, cacheType);
        } else {
            clazz.getEnclosedElements().addAll(fields);
        }
    }
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) Node(com.oracle.truffle.api.nodes.Node) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) ArrayList(java.util.ArrayList) NodeCost(com.oracle.truffle.api.nodes.NodeCost) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) Assumption(com.oracle.truffle.api.Assumption) 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) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) Cached(com.oracle.truffle.api.dsl.Cached) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) Modifier(javax.lang.model.element.Modifier) Child(com.oracle.truffle.api.nodes.Node.Child) NodeInterface(com.oracle.truffle.api.nodes.NodeInterface) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression)

Example 5 with Parameter

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

the class FlatNodeGenFactory method accessesCachedState.

private static boolean accessesCachedState(List<SpecializationData> specializations) {
    final AtomicBoolean needsState = new AtomicBoolean(false);
    for (final SpecializationData specialization : specializations) {
        if (!specialization.getAssumptionExpressions().isEmpty()) {
            needsState.set(true);
            break;
        }
        for (GuardExpression expression : specialization.getGuards()) {
            expression.getExpression().accept(new DSLExpressionVisitor() {

                public void visitVariable(Variable binary) {
                    if (!needsState.get() && isVariableAccessMember(binary)) {
                        needsState.set(true);
                    }
                }

                private boolean isVariableAccessMember(Variable variable) {
                    if (variable.getName().equals("null") && variable.getReceiver() == null) {
                        return false;
                    }
                    Parameter p = specialization.findByVariable(variable.getResolvedVariable());
                    if (p == null && !variable.getResolvedVariable().getModifiers().contains(STATIC)) {
                        DSLExpression receiver = variable.getReceiver();
                        if (receiver instanceof Variable) {
                            return isVariableAccessMember((Variable) receiver);
                        } else if (receiver instanceof Call) {
                            return isMethodAccessMember((Call) receiver);
                        }
                        return true;
                    } else if (p != null && p.getSpecification().isCached()) {
                        return true;
                    }
                    return false;
                }

                public void visitBooleanLiteral(BooleanLiteral binary) {
                }

                public void visitNegate(Negate negate) {
                }

                public void visitIntLiteral(IntLiteral binary) {
                }

                private boolean isMethodAccessMember(Call call) {
                    if (!call.getResolvedMethod().getModifiers().contains(STATIC)) {
                        DSLExpression receiver = call.getReceiver();
                        if (receiver instanceof Variable) {
                            return isVariableAccessMember((Variable) receiver);
                        } else if (receiver instanceof Call) {
                            return isMethodAccessMember((Call) receiver);
                        }
                        return true;
                    }
                    return false;
                }

                public void visitCall(Call call) {
                    if (!needsState.get() && isMethodAccessMember(call)) {
                        needsState.set(true);
                    }
                }

                public void visitBinary(Binary binary) {
                }
            });
        }
    }
    boolean needsStat = needsState.get();
    return needsStat;
}
Also used : Call(com.oracle.truffle.dsl.processor.expression.DSLExpression.Call) Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) BooleanLiteral(com.oracle.truffle.dsl.processor.expression.DSLExpression.BooleanLiteral) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) IntLiteral(com.oracle.truffle.dsl.processor.expression.DSLExpression.IntLiteral) Negate(com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate) Binary(com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary) DSLExpressionVisitor(com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionVisitor)

Aggregations

Parameter (com.oracle.truffle.dsl.processor.model.Parameter)16 ArrayList (java.util.ArrayList)10 TypeMirror (javax.lang.model.type.TypeMirror)9 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)8 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)8 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)7 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)6 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)6 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)4 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)4 VariableElement (javax.lang.model.element.VariableElement)4 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)3 TypeGuard (com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)3 Cached (com.oracle.truffle.api.dsl.Cached)2 Node (com.oracle.truffle.api.nodes.Node)2 NodeInterface (com.oracle.truffle.api.nodes.NodeInterface)2 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)2 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)2 DSLExpressionResolver (com.oracle.truffle.dsl.processor.expression.DSLExpressionResolver)2 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)2