Search in sources :

Example 46 with Event

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

the class ThreadSymmetry method createMappings.

private void createMappings() {
    for (Thread thread : program.getThreads()) {
        Map<Integer, Event> mapping = symmMap.computeIfAbsent(thread, key -> new HashMap<>());
        thread.getEvents().forEach(e -> mapping.put(e.getFId(), e));
    }
    Set<? extends EquivalenceClass<Thread>> classes = getAllEquivalenceClasses();
    for (EquivalenceClass<Thread> clazz : classes) {
        int size = symmMap.get(clazz.getRepresentative()).size();
        for (Thread t : clazz) {
            if (symmMap.get(t).size() == size) {
                Verify.verify(symmMap.get(t).size() == size, "Symmetric threads T%s and T%s have different number of events: %s vs. %s", clazz.getRepresentative(), t, size, symmMap.get(t).size());
            }
        }
    }
}
Also used : Event(com.dat3m.dartagnan.program.event.core.Event) Thread(com.dat3m.dartagnan.program.Thread)

Example 47 with Event

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

the class EndAtomic method runLocalAnalysis.

@Override
public void runLocalAnalysis(Program program, Context context) {
    // ===== Temporary fix to rematch atomic blocks correctly =====
    BranchEquivalence eq = context.requires(BranchEquivalence.class);
    List<Event> begins = this.thread.getEvents().stream().filter(x -> x instanceof BeginAtomic && eq.isReachableFrom(x, this)).collect(Collectors.toList());
    this.begin = (BeginAtomic) begins.get(begins.size() - 1);
    // =======================================================
    findEnclosedEvents(eq);
}
Also used : SVCOMPATOMIC(com.dat3m.dartagnan.program.event.Tag.SVCOMP.SVCOMPATOMIC) BranchEquivalence(com.dat3m.dartagnan.program.analysis.BranchEquivalence) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RMW(com.dat3m.dartagnan.program.event.Tag.RMW) Context(com.dat3m.dartagnan.verification.Context) List(java.util.List) Logger(org.apache.logging.log4j.Logger) EventVisitor(com.dat3m.dartagnan.program.event.visitors.EventVisitor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) BranchEquivalence(com.dat3m.dartagnan.program.analysis.BranchEquivalence) Event(com.dat3m.dartagnan.program.event.core.Event)

Example 48 with Event

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

the class Relation method getExecPair.

protected BooleanFormula getExecPair(Event e1, Event e2, SolverContext ctx) {
    if (e1.exec() == e2.exec()) {
        return e1.exec();
    }
    if (e1.getCId() > e2.getCId()) {
        Event temp = e1;
        e1 = e2;
        e2 = temp;
    }
    ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
    if (exec.isImplied(e1, e2)) {
        return e1.exec();
    } else if (exec.isImplied(e2, e1)) {
        return e2.exec();
    }
    return ctx.getFormulaManager().getBooleanFormulaManager().and(e1.exec(), e2.exec());
}
Also used : ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Event(com.dat3m.dartagnan.program.event.core.Event)

Example 49 with Event

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

the class BasicRegRelation method doEncodeApprox.

BooleanFormula doEncodeApprox(Collection<Event> regReaders, SolverContext ctx) {
    FormulaManager fmgr = ctx.getFormulaManager();
    BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
    for (Event regReader : regReaders) {
        Set<Tuple> writerReaders = maxTupleSet.getBySecond(regReader);
        for (Register register : getRegisters(regReader)) {
            List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
            List<Event> possibleWriters = writers.stream().filter(x -> writerReaders.contains(new Tuple(x, regReader))).collect(Collectors.toList());
            if (writers.isEmpty() || writers.get(0).getCId() >= regReader.getCId()) {
                BooleanFormula equal = generalEqual(register.toIntFormula(regReader, ctx), new IValue(BigInteger.ZERO, register.getPrecision()).toIntFormula(ctx), ctx);
                enc = bmgr.and(enc, equal);
            } else {
                for (int i = 0; i < possibleWriters.size(); i++) {
                    Event regWriter = possibleWriters.get(i);
                    // RegReader uses the value of RegWriter if it is executed ..
                    BooleanFormula clause = getExecPair(regWriter, regReader, ctx);
                    BooleanFormula edge = this.getSMTVar(regWriter, regReader, ctx);
                    // .. and no other write to the same register is executed in between
                    for (int j = i + 1; j < possibleWriters.size(); j++) {
                        clause = bmgr.and(clause, bmgr.not(possibleWriters.get(j).exec()));
                    }
                    // Encode edge and value binding
                    enc = bmgr.and(enc, bmgr.equivalence(edge, clause));
                    BooleanFormula equal = generalEqual(((RegWriter) regWriter).getResultRegisterExpr(), register.toIntFormula(regReader, ctx), ctx);
                    enc = bmgr.and(enc, bmgr.implication(edge, equal));
                }
            }
        }
    }
    return enc;
}
Also used : FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Collection(java.util.Collection) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) Collectors(java.util.stream.Collectors) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) SolverContext(org.sosy_lab.java_smt.api.SolverContext) IValue(com.dat3m.dartagnan.expression.IValue) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) StaticRelation(com.dat3m.dartagnan.wmm.relation.base.stat.StaticRelation) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) ImmutableList(com.google.common.collect.ImmutableList) IValue(com.dat3m.dartagnan.expression.IValue) FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Register(com.dat3m.dartagnan.program.Register) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 50 with Event

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

the class BasicRegRelation method mkTupleSets.

void mkTupleSets(Collection<Event> regReaders) {
    maxTupleSet = new TupleSet();
    minTupleSet = new TupleSet();
    ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
    ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
    for (Event regReader : regReaders) {
        for (Register register : getRegisters(regReader)) {
            List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
            // =============== Reduce set of writes ==================
            // TODO: We assume that any Register-Write is always executed
            // if it is contained in the program flow
            // This may fail for RMWReadCond?! It seems to work fine for the litmus tests though.
            // =========================
            List<Event> possibleWriters = writers.stream().filter(x -> x.getCId() < regReader.getCId() && !exec.areMutuallyExclusive(x, regReader)).collect(Collectors.toList());
            List<Event> impliedWriters = possibleWriters.stream().filter(x -> exec.isImplied(regReader, x)).collect(Collectors.toList());
            if (!impliedWriters.isEmpty()) {
                Event lastImplied = impliedWriters.get(impliedWriters.size() - 1);
                possibleWriters.removeIf(x -> x.getCId() < lastImplied.getCId());
            }
            possibleWriters.removeIf(x -> possibleWriters.stream().anyMatch(y -> x.getCId() < y.getCId() && exec.isImplied(x, y)));
            // --- Min sets ---
            if (possibleWriters.size() == 1) {
                // there is only a single regWriter
                minTupleSet.add(new Tuple(possibleWriters.stream().findAny().get(), regReader));
            } else {
                // there are multiple regWriters, but some are exclusive to all others
                for (Event writer : possibleWriters) {
                    if (possibleWriters.stream().allMatch(x -> x == writer || exec.areMutuallyExclusive(x, writer))) {
                        minTupleSet.add(new Tuple(writer, regReader));
                    }
                }
            }
            // --- Max sets ---
            for (Event regWriter : possibleWriters) {
                maxTupleSet.add(new Tuple(regWriter, regReader));
            }
        }
    }
}
Also used : FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Collection(java.util.Collection) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) Collectors(java.util.stream.Collectors) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) SolverContext(org.sosy_lab.java_smt.api.SolverContext) IValue(com.dat3m.dartagnan.expression.IValue) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) StaticRelation(com.dat3m.dartagnan.wmm.relation.base.stat.StaticRelation) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Register(com.dat3m.dartagnan.program.Register) ImmutableList(com.google.common.collect.ImmutableList) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

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