Search in sources :

Example 1 with MemEvent

use of com.dat3m.dartagnan.program.event.core.MemEvent in project Dat3M by hernanponcedeleon.

the class Refiner method permuteAndConvert.

// Changes a reasoning <literal> based on a given permutation <perm> and translates the result
// into a BooleanFormula for Refinement.
private BooleanFormula permuteAndConvert(CoreLiteral literal, Function<Event, Event> perm, SolverContext context) {
    BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc;
    if (literal instanceof ExecLiteral) {
        ExecLiteral lit = (ExecLiteral) literal;
        enc = perm.apply(lit.getData()).exec();
    } else if (literal instanceof AddressLiteral) {
        AddressLiteral loc = (AddressLiteral) literal;
        MemEvent e1 = (MemEvent) perm.apply(loc.getFirst());
        MemEvent e2 = (MemEvent) perm.apply(loc.getSecond());
        enc = generalEqual(e1.getMemAddressExpr(), e2.getMemAddressExpr(), context);
    } else if (literal instanceof RelLiteral) {
        RelLiteral lit = (RelLiteral) literal;
        Relation rel = task.getMemoryModel().getRelationRepository().getRelation(lit.getName());
        enc = rel.getSMTVar(perm.apply(lit.getData().getFirst()), perm.apply(lit.getData().getSecond()), context);
    } else {
        throw new IllegalArgumentException("CoreLiteral " + literal.toString() + " is not supported");
    }
    return literal.isNegative() ? bmgr.not(enc) : enc;
}
Also used : ExecLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.ExecLiteral) Relation(com.dat3m.dartagnan.wmm.relation.Relation) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) AddressLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.AddressLiteral) RelLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.RelLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Example 2 with MemEvent

use of com.dat3m.dartagnan.program.event.core.MemEvent in project Dat3M by hernanponcedeleon.

the class ExecutionGraphVisualizer method eventToNode.

private String eventToNode(EventData e, ExecutionModel model) {
    if (e.isInit()) {
        return String.format("\"I(%s, %d)\"", addresses.get(e.getAccessedAddress()), e.getValue());
    } else if (e.getEvent().getCLine() == -1) {
        // Special write of each thread
        int threadSize = model.getThreadEventsMap().get(e.getThread()).size();
        if (e.getLocalId() <= threadSize / 2) {
            return String.format("\"T%d:start\"", e.getThread().getId());
        } else {
            return String.format("\"T%d:end\"", e.getThread().getId());
        }
    }
    // We have MemEvent + Fence
    String tag = e.getEvent().toString();
    if (e.isMemoryEvent()) {
        Object address = addresses.get(e.getAccessedAddress());
        BigInteger value = e.getValue();
        String mo = ofNullable(((MemEvent) e.getEvent()).getMo()).orElse("NA");
        tag = e.isWrite() ? String.format("W(%s, %d, %s)", address, value, mo) : String.format("%d = R(%s, %s)", value, address, mo);
    }
    return String.format("\"T%d:E%s (%s:L%d)\\n%s\"", e.getThread().getId(), e.getEvent().getCId(), e.getEvent().getSourceCodeFile(), e.getEvent().getCLine(), tag);
}
Also used : MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) BigInteger(java.math.BigInteger)

Example 3 with MemEvent

use of com.dat3m.dartagnan.program.event.core.MemEvent in project Dat3M by hernanponcedeleon.

the class WitnessBuilder method getSCExecutionOrder.

private List<Event> getSCExecutionOrder(Model model) {
    List<Event> execEvents = new ArrayList<>();
    // TODO: we recently added many cline to many events and this might affect the witness generation.
    Predicate<Event> executedCEvents = e -> e.wasExecuted(model) && e.getCLine() > -1;
    execEvents.addAll(task.getProgram().getCache().getEvents(FilterBasic.get(Tag.INIT)).stream().filter(executedCEvents).collect(Collectors.toList()));
    execEvents.addAll(task.getProgram().getEvents().stream().filter(executedCEvents).collect(Collectors.toList()));
    Map<Integer, List<Event>> map = new HashMap<>();
    for (Event e : execEvents) {
        // TODO improve this: these events correspond to return statements
        if (e instanceof MemEvent && ((MemEvent) e).getMemValue() instanceof BConst && !((BConst) ((MemEvent) e).getMemValue()).getValue()) {
            continue;
        }
        BigInteger var = model.evaluate(intVar("hb", e, ctx));
        if (var != null) {
            map.computeIfAbsent(var.intValue(), x -> new ArrayList<>()).add(e);
        }
    }
    List<Event> exec = map.keySet().stream().sorted().flatMap(key -> map.get(key).stream()).collect(Collectors.toList());
    return exec.isEmpty() ? execEvents : exec;
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) Utils.intVar(com.dat3m.dartagnan.wmm.utils.Utils.intVar) MessageDigest(java.security.MessageDigest) SimpleDateFormat(java.text.SimpleDateFormat) EdgeAttributes(com.dat3m.dartagnan.witness.EdgeAttributes) Thread(com.dat3m.dartagnan.program.Thread) WITNESS_ORIGINAL_PROGRAM_PATH(com.dat3m.dartagnan.configuration.OptionNames.WITNESS_ORIGINAL_PROGRAM_PATH) EndAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic) Model(org.sosy_lab.java_smt.api.Model) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) Option(org.sosy_lab.common.configuration.Option) Result(com.dat3m.dartagnan.utils.Result) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) BigInteger(java.math.BigInteger) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) DateFormat(java.text.DateFormat) PTHREAD(com.dat3m.dartagnan.program.event.Tag.C11.PTHREAD) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) Store(com.dat3m.dartagnan.program.event.core.Store) GraphAttributes(com.dat3m.dartagnan.witness.GraphAttributes) Predicate(java.util.function.Predicate) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) File(java.io.File) Tag(com.dat3m.dartagnan.program.event.Tag) WRITE(com.dat3m.dartagnan.program.event.Tag.WRITE) String.valueOf(java.lang.String.valueOf) SolverException(org.sosy_lab.java_smt.api.SolverException) Event(com.dat3m.dartagnan.program.event.core.Event) BConst(com.dat3m.dartagnan.expression.BConst) Load(com.dat3m.dartagnan.program.event.core.Load) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) FAIL(com.dat3m.dartagnan.utils.Result.FAIL) BigInteger(java.math.BigInteger) BConst(com.dat3m.dartagnan.expression.BConst) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) BigInteger(java.math.BigInteger)

Example 4 with MemEvent

use of com.dat3m.dartagnan.program.event.core.MemEvent 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 5 with MemEvent

use of com.dat3m.dartagnan.program.event.core.MemEvent in project Dat3M by hernanponcedeleon.

the class RelLoc method getMaxTupleSet.

@Override
public TupleSet getMaxTupleSet() {
    if (maxTupleSet == null) {
        AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
        maxTupleSet = new TupleSet();
        Collection<Event> events = task.getProgram().getCache().getEvents(FilterBasic.get(MEMORY));
        for (Event e1 : events) {
            for (Event e2 : events) {
                if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
                    maxTupleSet.add(new Tuple(e1, e2));
                }
            }
        }
        removeMutuallyExclusiveTuples(maxTupleSet);
    }
    return maxTupleSet;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Aggregations

MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)17 Event (com.dat3m.dartagnan.program.event.core.Event)12 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)8 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)8 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)6 Thread (com.dat3m.dartagnan.program.Thread)5 Tag (com.dat3m.dartagnan.program.event.Tag)5 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)5 WmmAnalysis (com.dat3m.dartagnan.wmm.analysis.WmmAnalysis)5 Collectors (java.util.stream.Collectors)5 Program (com.dat3m.dartagnan.program.Program)4 Register (com.dat3m.dartagnan.program.Register)4 Load (com.dat3m.dartagnan.program.event.core.Load)4 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)4 java.util (java.util)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 Store (com.dat3m.dartagnan.program.event.core.Store)3 RegReaderData (com.dat3m.dartagnan.program.event.core.utils.RegReaderData)3 EndAtomic (com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic)3