Search in sources :

Example 51 with Event

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

the class EventCache method getRegWriterMap.

public ImmutableMap<Register, ImmutableList<Event>> getRegWriterMap() {
    if (regWriterMap == null) {
        Map<Register, List<Event>> regEventMap = new HashMap<>();
        List<Event> regWriters = getEvents(FilterBasic.get(Tag.REG_WRITER));
        for (Event e : regWriters) {
            Register register = ((RegWriter) e).getResultRegister();
            regEventMap.computeIfAbsent(register, key -> new ArrayList<>(regWriters.size())).add(e);
        }
        ImmutableMap.Builder<Register, ImmutableList<Event>> builder = new ImmutableMap.Builder<>();
        for (Register register : regEventMap.keySet()) {
            List<Event> list = regEventMap.get(register);
            Collections.sort(list);
            builder.put(register, ImmutableList.copyOf(list));
        }
        regWriterMap = builder.build();
    }
    return regWriterMap;
}
Also used : FilterAbstract(com.dat3m.dartagnan.program.filter.FilterAbstract) java.util(java.util) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Event(com.dat3m.dartagnan.program.event.core.Event) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Event(com.dat3m.dartagnan.program.event.core.Event) ImmutableList(com.google.common.collect.ImmutableList)

Example 52 with Event

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

the class LoopUnrolling method updateAssertions.

private void updateAssertions(Program program) {
    if (program.getAss() != null) {
        // but I was under the impression that assFilter was used for Litmus tests.
        return;
    }
    List<Event> assertions = new ArrayList<>();
    for (Thread t : program.getThreads()) {
        assertions.addAll(t.getCache().getEvents(FilterBasic.get(Tag.ASSERTION)));
    }
    AbstractAssert ass = new AssertTrue();
    if (!assertions.isEmpty()) {
        ass = new AssertInline((Local) assertions.get(0));
        for (int i = 1; i < assertions.size(); i++) {
            ass = new AssertCompositeOr(ass, new AssertInline((Local) assertions.get(i)));
        }
    }
    program.setAss(ass);
    logger.info("Updated assertions after unrolling.");
}
Also used : AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) ArrayList(java.util.ArrayList) Event(com.dat3m.dartagnan.program.event.core.Event) Local(com.dat3m.dartagnan.program.event.core.Local) AbstractAssert(com.dat3m.dartagnan.asserts.AbstractAssert) AssertCompositeOr(com.dat3m.dartagnan.asserts.AssertCompositeOr) Thread(com.dat3m.dartagnan.program.Thread) AssertInline(com.dat3m.dartagnan.asserts.AssertInline)

Example 53 with Event

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

the class ProgramEncoder method encodeFinalRegisterValues.

public BooleanFormula encodeFinalRegisterValues(SolverContext ctx) {
    checkInitialized();
    logger.info("Encoding final register values");
    FormulaManager fmgr = ctx.getFormulaManager();
    BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    for (Map.Entry<Register, Dependency.State> e : dep.finalWriters().entrySet()) {
        Formula value = e.getKey().getLastValueExpr(ctx);
        Dependency.State state = e.getValue();
        List<Event> writers = state.may;
        if (initializeRegisters && !state.initialized) {
            BooleanFormula clause = generalEqualZero(value, ctx);
            for (Event w : writers) {
                clause = bmgr.or(clause, w.exec());
            }
            enc = bmgr.and(enc, clause);
        }
        for (int i = 0; i < writers.size(); i++) {
            Event writer = writers.get(i);
            BooleanFormula clause = bmgr.or(generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx), bmgr.not(writer.exec()));
            for (Event w : writers.subList(i + 1, writers.size())) {
                if (!exec.areMutuallyExclusive(writer, w)) {
                    clause = bmgr.or(clause, w.exec());
                }
            }
            enc = bmgr.and(enc, clause);
        }
    }
    return enc;
}
Also used : Dependency(com.dat3m.dartagnan.program.analysis.Dependency) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Event(com.dat3m.dartagnan.program.event.core.Event)

Example 54 with Event

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

the class ProgramEncoder method execution.

/**
 * Simple formula proposing the execution of two events.
 * Does not test for mutual exclusion.
 * @param first
 * Some event of a program to be encoded.
 * @param second
 * Another event of the same program.
 * @param exec
 * Analysis performed on the associated program.
 * @param ctx
 * Builder of expressions and formulas.
 * @return
 * Proposition that both {@code first} and {@code second} are included in the modelled execution.
 */
public static BooleanFormula execution(Event first, Event second, ExecutionAnalysis exec, SolverContext ctx) {
    boolean b = first.getCId() < second.getCId();
    Event x = b ? first : second;
    Event y = b ? second : first;
    if (x.exec() == y.exec() || exec.isImplied(x, y)) {
        return x.exec();
    }
    if (exec.isImplied(y, x)) {
        return y.exec();
    }
    return ctx.getFormulaManager().getBooleanFormulaManager().and(x.exec(), y.exec());
}
Also used : Event(com.dat3m.dartagnan.program.event.core.Event)

Example 55 with Event

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

the class PropertyEncoder method encodeDataRaces.

public BooleanFormula encodeDataRaces(SolverContext ctx) {
    final String hb = "hb";
    checkState(memoryModel.getAxioms().stream().anyMatch(ax -> ax.isAcyclicity() && ax.getRelation().getName().equals(hb)), "The provided WMM needs an 'acyclic(hb)' axiom to encode data races.");
    logger.info("Encoding data-races");
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    IntegerFormulaManager imgr = ctx.getFormulaManager().getIntegerFormulaManager();
    BooleanFormula enc = bmgr.makeFalse();
    for (Thread t1 : program.getThreads()) {
        for (Thread t2 : program.getThreads()) {
            if (t1.getId() == t2.getId()) {
                continue;
            }
            for (Event e1 : t1.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.WRITE), FilterBasic.get(Tag.INIT)))) {
                MemEvent w = (MemEvent) e1;
                for (Event e2 : t2.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.MEMORY), FilterBasic.get(Tag.INIT)))) {
                    MemEvent m = (MemEvent) e2;
                    if (w.hasFilter(Tag.RMW) && m.hasFilter(Tag.RMW)) {
                        continue;
                    }
                    if (w.canRace() && m.canRace() && alias.mayAlias(w, m)) {
                        BooleanFormula conflict = bmgr.and(m.exec(), w.exec(), edge(hb, m, w, ctx), generalEqual(w.getMemAddressExpr(), m.getMemAddressExpr(), ctx), imgr.equal(intVar(hb, w, ctx), imgr.add(intVar(hb, m, ctx), imgr.makeNumber(BigInteger.ONE))));
                        enc = bmgr.or(enc, conflict);
                    }
                }
            }
        }
    }
    // We use the SMT variable to extract from the model if the property was violated
    enc = bmgr.equivalence(RACES.getSMTVariable(ctx), enc);
    return bmgr.and(RACES.getSMTVariable(ctx), enc);
}
Also used : Options(org.sosy_lab.common.configuration.Options) Property(com.dat3m.dartagnan.configuration.Property) Utils.intVar(com.dat3m.dartagnan.wmm.utils.Utils.intVar) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Utils.edge(com.dat3m.dartagnan.wmm.utils.Utils.edge) HashMap(java.util.HashMap) Thread(com.dat3m.dartagnan.program.Thread) ArrayList(java.util.ArrayList) Wmm(com.dat3m.dartagnan.wmm.Wmm) Map(java.util.Map) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) EnumSet(java.util.EnumSet) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) RelCo(com.dat3m.dartagnan.wmm.relation.base.memory.RelCo) Configuration(org.sosy_lab.common.configuration.Configuration) Collectors(java.util.stream.Collectors) Label(com.dat3m.dartagnan.program.event.core.Label) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) Tag(com.dat3m.dartagnan.program.event.Tag) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Context(com.dat3m.dartagnan.verification.Context) RelationNameRepository(com.dat3m.dartagnan.wmm.relation.RelationNameRepository) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) Load(com.dat3m.dartagnan.program.event.core.Load) LogManager(org.apache.logging.log4j.LogManager) FilterMinus(com.dat3m.dartagnan.program.filter.FilterMinus) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Thread(com.dat3m.dartagnan.program.Thread)

Aggregations

Event (com.dat3m.dartagnan.program.event.core.Event)104 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)34 Thread (com.dat3m.dartagnan.program.Thread)32 Register (com.dat3m.dartagnan.program.Register)25 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)25 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)20 Tag (com.dat3m.dartagnan.program.event.Tag)16 Label (com.dat3m.dartagnan.program.event.core.Label)16 Collectors (java.util.stream.Collectors)16 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)16 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)16 LogManager (org.apache.logging.log4j.LogManager)15 Logger (org.apache.logging.log4j.Logger)15 Program (com.dat3m.dartagnan.program.Program)12 ExecutionAnalysis (com.dat3m.dartagnan.program.analysis.ExecutionAnalysis)12 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)12 java.util (java.util)12 SolverContext (org.sosy_lab.java_smt.api.SolverContext)12 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)11 CondJump (com.dat3m.dartagnan.program.event.core.CondJump)10