Search in sources :

Example 1 with IExpr

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

the class RelCo method encodeApprox.

@Override
protected BooleanFormula encodeApprox(SolverContext ctx) {
    AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
    WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
    FormulaManager fmgr = ctx.getFormulaManager();
    BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
    IntegerFormulaManager imgr = fmgr.getIntegerFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    List<Event> eventsInit = task.getProgram().getCache().getEvents(FilterBasic.get(INIT));
    List<Event> eventsStore = task.getProgram().getCache().getEvents(FilterMinus.get(FilterBasic.get(WRITE), FilterBasic.get(INIT)));
    for (Event e : eventsInit) {
        enc = bmgr.and(enc, imgr.equal(getIntVar(e, ctx), imgr.makeNumber(BigInteger.ZERO)));
    }
    List<IntegerFormula> intVars = new ArrayList<>();
    for (Event w : eventsStore) {
        IntegerFormula coVar = getIntVar(w, ctx);
        enc = bmgr.and(enc, imgr.greaterThan(coVar, imgr.makeNumber(BigInteger.ZERO)));
        intVars.add(coVar);
    }
    BooleanFormula distinct = intVars.size() > 1 ? imgr.distinct(intVars) : bmgr.makeTrue();
    enc = bmgr.and(enc, distinct);
    for (Event w : task.getProgram().getCache().getEvents(FilterBasic.get(WRITE))) {
        MemEvent w1 = (MemEvent) w;
        BooleanFormula lastCo = w1.exec();
        for (Tuple t : maxTupleSet.getByFirst(w1)) {
            MemEvent w2 = (MemEvent) t.getSecond();
            BooleanFormula relation = getSMTVar(t, ctx);
            BooleanFormula execPair = getExecPair(t, ctx);
            lastCo = bmgr.and(lastCo, bmgr.not(relation));
            Formula a1 = w1.getMemAddressExpr();
            Formula a2 = w2.getMemAddressExpr();
            BooleanFormula sameAddress = generalEqual(a1, a2, ctx);
            enc = bmgr.and(enc, bmgr.equivalence(relation, bmgr.and(execPair, sameAddress, imgr.lessThan(getIntVar(w1, ctx), getIntVar(w2, ctx)))));
            // ============ Local consistency optimizations ============
            if (getMinTupleSet().contains(t)) {
                enc = bmgr.and(enc, bmgr.equivalence(relation, execPair));
            } else if (wmmAnalysis.isLocallyConsistent()) {
                if (w2.is(INIT) || t.isBackward()) {
                    enc = bmgr.and(enc, bmgr.equivalence(relation, bmgr.makeFalse()));
                }
                if (w1.is(INIT) || t.isForward()) {
                    enc = bmgr.and(enc, bmgr.implication(bmgr.and(execPair, sameAddress), relation));
                }
            }
        }
        if (task.getProgram().getFormat().equals(LITMUS) || task.getProperty().contains(LIVENESS)) {
            BooleanFormula lastCoExpr = getLastCoVar(w1, ctx);
            enc = bmgr.and(enc, bmgr.equivalence(lastCoExpr, lastCo));
            for (Event i : eventsInit) {
                Init init = (Init) i;
                if (!alias.mayAlias(w1, init)) {
                    continue;
                }
                IExpr address = init.getAddress();
                Formula a1 = w1.getMemAddressExpr();
                Formula a2 = address.toIntFormula(init, ctx);
                BooleanFormula sameAddress = generalEqual(a1, a2, ctx);
                Formula v1 = w1.getMemValueExpr();
                Formula v2 = init.getBase().getLastMemValueExpr(ctx, init.getOffset());
                BooleanFormula sameValue = generalEqual(v1, v2, ctx);
                enc = bmgr.and(enc, bmgr.implication(bmgr.and(lastCoExpr, sameAddress), sameValue));
            }
        }
    }
    return enc;
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ArrayList(java.util.ArrayList) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Init(com.dat3m.dartagnan.program.event.core.Init) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) WmmAnalysis(com.dat3m.dartagnan.wmm.analysis.WmmAnalysis) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) IExpr(com.dat3m.dartagnan.expression.IExpr) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 2 with IExpr

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

the class VisitorBase method visitRMW.

@Override
public List<Event> visitRMW(RMW e) {
    Register resultRegister = e.getResultRegister();
    IExpr address = e.getAddress();
    String mo = e.getMo();
    Register dummyReg = e.getThread().newRegister(resultRegister.getPrecision());
    Load load = newRMWLoad(dummyReg, address, mo);
    RMWStore store = newRMWStore(load, address, e.getMemValue(), mo);
    return eventSequence(load, store, newLocal(resultRegister, dummyReg));
}
Also used : Load(com.dat3m.dartagnan.program.event.core.Load) Register(com.dat3m.dartagnan.program.Register) RMWStore(com.dat3m.dartagnan.program.event.core.rmw.RMWStore) IExpr(com.dat3m.dartagnan.expression.IExpr)

Example 3 with IExpr

use of com.dat3m.dartagnan.expression.IExpr 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 4 with IExpr

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

the class AtomicProcedures method atomicXchg.

private static void atomicXchg(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;
    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.newExchange(reg, add, value, mo)).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
}
Also used : Register(com.dat3m.dartagnan.program.Register) IExpr(com.dat3m.dartagnan.expression.IExpr) IConst(com.dat3m.dartagnan.expression.IConst)

Example 5 with IExpr

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

the class AtomicProcedures method atomicStore.

private static void atomicStore(VisitorBoogie visitor, Call_cmdContext ctx) {
    IExpr add = (IExpr) ctx.call_params().exprs().expr().get(0).accept(visitor);
    ExprInterface value = (ExprInterface) ctx.call_params().exprs().expr().get(1).accept(visitor);
    String mo = null;
    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.newStore(add, value, mo)).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
}
Also used : ExprInterface(com.dat3m.dartagnan.expression.ExprInterface) IExpr(com.dat3m.dartagnan.expression.IExpr) IConst(com.dat3m.dartagnan.expression.IConst)

Aggregations

IExpr (com.dat3m.dartagnan.expression.IExpr)23 Register (com.dat3m.dartagnan.program.Register)16 IConst (com.dat3m.dartagnan.expression.IConst)7 IExprBin (com.dat3m.dartagnan.expression.IExprBin)6 ExprInterface (com.dat3m.dartagnan.expression.ExprInterface)4 IValue (com.dat3m.dartagnan.expression.IValue)4 BigInteger (java.math.BigInteger)4 ExprsContext (com.dat3m.dartagnan.parsers.BoogieParser.ExprsContext)2 Event (com.dat3m.dartagnan.program.event.core.Event)2 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)2 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)2 ParsingException (com.dat3m.dartagnan.exception.ParsingException)1 Atom (com.dat3m.dartagnan.expression.Atom)1 IOpBin (com.dat3m.dartagnan.expression.op.IOpBin)1 PLUS (com.dat3m.dartagnan.expression.op.IOpBin.PLUS)1 ExprContext (com.dat3m.dartagnan.parsers.BoogieParser.ExprContext)1 Program (com.dat3m.dartagnan.program.Program)1 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)1 Tag (com.dat3m.dartagnan.program.event.Tag)1 com.dat3m.dartagnan.program.event.core (com.dat3m.dartagnan.program.event.core)1