Search in sources :

Example 1 with BOpUn

use of com.dat3m.dartagnan.expression.op.BOpUn in project Dat3M by hernanponcedeleon.

the class ConstantPropagation method evaluate.

// TODO Once we have a lattice class this should be moved there.
private ExprInterface evaluate(ExprInterface input, Map<Register, ExprInterface> map) {
    ExprSimplifier simplifier = new ExprSimplifier();
    if (input instanceof INonDet || input instanceof BNonDet) {
        return TOP;
    }
    if (input instanceof IConst || input instanceof BConst) {
        return input;
    }
    if (input instanceof Register) {
        // have the key in the map.
        return map.getOrDefault(input, input);
    }
    if (input instanceof IExprUn) {
        IExprUn un = (IExprUn) input;
        IOpUn op = un.getOp();
        // These two can cause problems
        if (op.equals(BV2INT) || op.equals(BV2UINT)) {
            return input;
        }
        IExpr inner = (IExpr) evaluate(un.getInner(), map);
        return inner == TOP ? inner : new IExprUn(op, inner).visit(simplifier);
    }
    if (input instanceof IExprBin) {
        IExprBin bin = (IExprBin) input;
        IExpr lhs = (IExpr) evaluate(bin.getLHS(), map);
        IExpr rhs = (IExpr) evaluate(bin.getRHS(), map);
        return lhs == TOP || rhs == TOP ? TOP : new IExprBin(lhs, bin.getOp(), rhs).visit(simplifier);
    }
    if (input instanceof IfExpr) {
        IfExpr ife = (IfExpr) input;
        ExprInterface guard = evaluate(ife.getGuard(), map);
        IExpr tbranch = (IExpr) evaluate(ife.getTrueBranch(), map);
        IExpr fbranch = (IExpr) evaluate(ife.getFalseBranch(), map);
        return tbranch == TOP || fbranch == TOP || guard == TOP ? TOP : new IfExpr((BExpr) guard, tbranch, fbranch).visit(simplifier);
    }
    if (input instanceof Atom) {
        Atom atom = (Atom) input;
        ExprInterface lhs = evaluate(atom.getLHS(), map);
        ExprInterface rhs = evaluate(atom.getRHS(), map);
        return (lhs == TOP | rhs == TOP) ? TOP : new Atom(lhs, atom.getOp(), rhs).visit(simplifier);
    }
    if (input instanceof BExprUn) {
        BExprUn un = (BExprUn) input;
        BOpUn op = un.getOp();
        ExprInterface inner = evaluate(un.getInner(), map);
        return inner == TOP ? TOP : new BExprUn(op, inner).visit(simplifier);
    }
    if (input instanceof BExprBin) {
        BExprBin bin = (BExprBin) input;
        ExprInterface lhs = evaluate(bin.getLHS(), map);
        ExprInterface rhs = evaluate(bin.getRHS(), map);
        return (lhs == TOP | rhs == TOP) ? TOP : new BExprBin(lhs, bin.getOp(), rhs).visit(simplifier);
    }
    throw new UnsupportedOperationException(String.format("Expression %s not supported", input));
}
Also used : IOpUn(com.dat3m.dartagnan.expression.op.IOpUn) Register(com.dat3m.dartagnan.program.Register) ExprSimplifier(com.dat3m.dartagnan.expression.processing.ExprSimplifier) BOpUn(com.dat3m.dartagnan.expression.op.BOpUn)

Aggregations

BOpUn (com.dat3m.dartagnan.expression.op.BOpUn)1 IOpUn (com.dat3m.dartagnan.expression.op.IOpUn)1 ExprSimplifier (com.dat3m.dartagnan.expression.processing.ExprSimplifier)1 Register (com.dat3m.dartagnan.program.Register)1