Search in sources :

Example 1 with IOpBin

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

the class VisitorNone method visitAtomicFetchOp.

@Override
public List<Event> visitAtomicFetchOp(AtomicFetchOp e) {
    Register resultRegister = e.getResultRegister();
    IOpBin op = e.getOp();
    IExpr address = e.getAddress();
    String mo = e.getMo();
    Register dummyReg = new Register(null, resultRegister.getThreadId(), resultRegister.getPrecision());
    Load load = newRMWLoad(resultRegister, address, mo);
    return eventSequence(load, newLocal(dummyReg, new IExprBin(resultRegister, op, (IExpr) e.getMemValue())), newRMWStore(load, address, dummyReg, mo));
}
Also used : IOpBin(com.dat3m.dartagnan.expression.op.IOpBin) Register(com.dat3m.dartagnan.program.Register)

Example 2 with IOpBin

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

the class VisitorArm8 method visitAtomicFetchOp.

@Override
public List<Event> visitAtomicFetchOp(AtomicFetchOp e) {
    Register resultRegister = e.getResultRegister();
    IOpBin op = e.getOp();
    IExpr value = (IExpr) e.getMemValue();
    IExpr address = e.getAddress();
    String mo = e.getMo();
    Register dummyReg = e.getThread().newRegister(resultRegister.getPrecision());
    Local localOp = newLocal(dummyReg, new IExprBin(resultRegister, op, value));
    Load load = newRMWLoadExclusive(resultRegister, address, Tag.ARMv8.extractLoadMoFromCMo(mo));
    Store store = newRMWStoreExclusive(address, dummyReg, Tag.ARMv8.extractStoreMoFromCMo(mo), true);
    Label label = newLabel("FakeDep");
    Event fakeCtrlDep = newFakeCtrlDep(resultRegister, label);
    return eventSequence(load, fakeCtrlDep, label, localOp, store);
}
Also used : IOpBin(com.dat3m.dartagnan.expression.op.IOpBin) Register(com.dat3m.dartagnan.program.Register)

Example 3 with IOpBin

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

the class VisitorIMM method visitAtomicFetchOp.

@Override
public List<Event> visitAtomicFetchOp(AtomicFetchOp e) {
    Register resultRegister = e.getResultRegister();
    IOpBin op = e.getOp();
    IExpr address = e.getAddress();
    String mo = e.getMo();
    Fence optionalFence = mo.equals(Tag.C11.MO_SC) ? newFence(Tag.C11.MO_SC) : null;
    Register dummyReg = e.getThread().newRegister(resultRegister.getPrecision());
    Load load = newRMWLoad(resultRegister, address, extractLoadMo(mo));
    return eventSequence(optionalFence, load, newLocal(dummyReg, new IExprBin(resultRegister, op, (IExpr) e.getMemValue())), optionalFence, newRMWStore(load, address, dummyReg, extractStoreMo(mo)));
}
Also used : IOpBin(com.dat3m.dartagnan.expression.op.IOpBin) Register(com.dat3m.dartagnan.program.Register)

Example 4 with IOpBin

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

the class AtomicProcedures method atomicFetchOp.

private static void atomicFetchOp(VisitorBoogie visitor, Call_cmdContext ctx) {
    Register reg = visitor.programBuilder.getOrCreateRegister(visitor.threadCount, visitor.currentScope.getID() + ":" + ctx.call_params().Ident(0).getText(), ARCH_PRECISION);
    IExpr add = (IExpr) ctx.call_params().exprs().expr().get(0).accept(visitor);
    IExpr value = (IExpr) ctx.call_params().exprs().expr().get(1).accept(visitor);
    String mo = null;
    IOpBin op;
    if (ctx.getText().contains("_add")) {
        op = IOpBin.PLUS;
    } else if (ctx.getText().contains("_sub")) {
        op = IOpBin.MINUS;
    } else if (ctx.getText().contains("_and")) {
        op = IOpBin.AND;
    } else if (ctx.getText().contains("_or")) {
        op = IOpBin.OR;
    } else if (ctx.getText().contains("_xor")) {
        op = IOpBin.XOR;
    } else {
        throw new RuntimeException("AtomicFetchOp operation cannot be handled");
    }
    if (ctx.call_params().exprs().expr().size() > 2) {
        mo = intToMo(((IConst) ctx.call_params().exprs().expr().get(2).accept(visitor)).getValueAsInt());
    }
    visitor.programBuilder.addChild(visitor.threadCount, Atomic.newFetchOp(reg, add, value, op, mo)).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
}
Also used : IOpBin(com.dat3m.dartagnan.expression.op.IOpBin) Register(com.dat3m.dartagnan.program.Register) IExpr(com.dat3m.dartagnan.expression.IExpr) IConst(com.dat3m.dartagnan.expression.IConst)

Example 5 with IOpBin

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

the class ExprSimplifier method visit.

@Override
public IExpr visit(IExprBin iBin) {
    IExpr lhs = (IExpr) iBin.getLHS().visit(this);
    IExpr rhs = (IExpr) iBin.getRHS().visit(this);
    IOpBin op = iBin.getOp();
    if (lhs.equals(rhs)) {
        switch(op) {
            case AND:
            case OR:
                return lhs;
            case XOR:
                return IValue.ZERO;
        }
    }
    if (!(lhs instanceof IConst || rhs instanceof IConst)) {
        return new IExprBin(lhs, iBin.getOp(), rhs);
    } else if (lhs instanceof IConst && rhs instanceof IConst) {
        // We cannot call reduce for R_SHIFT (lack of implementation)
        if (!(lhs instanceof MemoryObject) && iBin.getOp() != R_SHIFT) {
            return new IExprBin(lhs, iBin.getOp(), rhs).reduce();
        }
        // Rule to reduce &mem + 0
        if (lhs instanceof MemoryObject && rhs.equals(IValue.ZERO)) {
            return lhs;
        }
    }
    if (lhs instanceof IConst) {
        IConst lc = (IConst) lhs;
        BigInteger val = lc.getValue();
        switch(op) {
            case MULT:
                return val.compareTo(BigInteger.ZERO) == 0 ? IValue.ZERO : val.equals(BigInteger.ONE) ? rhs : new IExprBin(lhs, op, rhs);
            case PLUS:
                return val.compareTo(BigInteger.ZERO) == 0 ? rhs : new IExprBin(lhs, op, rhs);
            default:
                return new IExprBin(lhs, op, rhs);
        }
    }
    IConst rc = (IConst) rhs;
    BigInteger val = rc.getValue();
    switch(op) {
        case MULT:
            return val.compareTo(BigInteger.ZERO) == 0 ? IValue.ZERO : val.equals(BigInteger.ONE) ? lhs : new IExprBin(lhs, op, rhs);
        case PLUS:
        case MINUS:
            if (val.compareTo(BigInteger.ZERO) == 0) {
                return lhs;
            }
            // e.g. (&mem + x) - y -> &mem + reduced(x - y)
            if (lhs instanceof IExprBin && ((IExprBin) lhs).getRHS() instanceof IConst) {
                IExprBin lhsBin = (IExprBin) lhs;
                IExpr newLHS = lhsBin.getLHS();
                IExpr newRHS = new IExprBin(lhsBin.getRHS(), lhsBin.getOp(), rhs).reduce();
                return new IExprBin(newLHS, op, newRHS);
            }
            return new IExprBin(lhs, op, rhs);
        default:
            return new IExprBin(lhs, op, rhs);
    }
}
Also used : IOpBin(com.dat3m.dartagnan.expression.op.IOpBin) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) BigInteger(java.math.BigInteger)

Aggregations

IOpBin (com.dat3m.dartagnan.expression.op.IOpBin)7 Register (com.dat3m.dartagnan.program.Register)6 IConst (com.dat3m.dartagnan.expression.IConst)1 IExpr (com.dat3m.dartagnan.expression.IExpr)1 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)1 BigInteger (java.math.BigInteger)1