Search in sources :

Example 1 with IOpUn

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

the class ConstantPropagation method evaluate.

// TODO Once we have a lattice class this should be moved there.
private IExpr evaluate(IExpr input, Map<Register, IExpr> map) {
    if (input instanceof INonDet) {
        return new ITop();
    }
    if (input instanceof IConst) {
        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 = evaluate(un.getInner(), map);
        return inner instanceof ITop ? inner : new IExprUn(op, inner);
    }
    if (input instanceof IExprBin) {
        IExprBin bin = (IExprBin) input;
        IExpr lhs = evaluate(bin.getLHS(), map);
        IExpr rhs = evaluate(bin.getRHS(), map);
        return lhs instanceof ITop ? lhs : rhs instanceof ITop ? rhs : new IExprBin(lhs, bin.getOp(), rhs);
    }
    if (input instanceof IfExpr) {
        IfExpr ife = (IfExpr) input;
        IExpr tbranch = evaluate(ife.getTrueBranch(), map);
        IExpr fbranch = evaluate(ife.getFalseBranch(), map);
        return tbranch instanceof ITop ? tbranch : fbranch instanceof ITop ? fbranch : new IfExpr(ife.getGuard(), tbranch, fbranch);
    }
    throw new UnsupportedOperationException(String.format("IExpr %s not supported", input));
}
Also used : Register(com.dat3m.dartagnan.program.Register) IOpUn(com.dat3m.dartagnan.expression.op.IOpUn)

Example 2 with IOpUn

use of com.dat3m.dartagnan.expression.op.IOpUn 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

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