Search in sources :

Example 1 with AbstractDSLExpressionVisitor

use of com.oracle.truffle.dsl.processor.expression.DSLExpression.AbstractDSLExpressionVisitor 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 AbstractDSLExpressionVisitor() {

                @Override
                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()) {
                        CacheExpression cache = specialization.findCache(p);
                        if (cache != null && cache.isAlwaysInitialized()) {
                            // allowed access as is initialized in fast path.
                            return false;
                        }
                        return true;
                    }
                    return false;
                }

                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;
                }

                @Override
                public void visitCall(Call call) {
                    if (!needsState.get() && isMethodAccessMember(call)) {
                        needsState.set(true);
                    }
                }
            });
        }
    }
    boolean needsStat = needsState.get();
    return needsStat;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Call(com.oracle.truffle.dsl.processor.expression.DSLExpression.Call) AbstractDSLExpressionVisitor(com.oracle.truffle.dsl.processor.expression.DSLExpression.AbstractDSLExpressionVisitor) Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression)

Aggregations

DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)1 AbstractDSLExpressionVisitor (com.oracle.truffle.dsl.processor.expression.DSLExpression.AbstractDSLExpressionVisitor)1 Call (com.oracle.truffle.dsl.processor.expression.DSLExpression.Call)1 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)1 CacheExpression (com.oracle.truffle.dsl.processor.model.CacheExpression)1 GuardExpression (com.oracle.truffle.dsl.processor.model.GuardExpression)1 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)1 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1