Search in sources :

Example 1 with IntLiteral

use of com.oracle.truffle.dsl.processor.expression.DSLExpression.IntLiteral 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

DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)1 Binary (com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary)1 BooleanLiteral (com.oracle.truffle.dsl.processor.expression.DSLExpression.BooleanLiteral)1 Call (com.oracle.truffle.dsl.processor.expression.DSLExpression.Call)1 DSLExpressionVisitor (com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionVisitor)1 IntLiteral (com.oracle.truffle.dsl.processor.expression.DSLExpression.IntLiteral)1 Negate (com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate)1 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)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