Search in sources :

Example 1 with EquivalenceClass

use of com.dat3m.dartagnan.utils.equivalence.EquivalenceClass in project Dat3M by hernanponcedeleon.

the class SymmetryEncoder method encodeSymmetryClass.

public BooleanFormula encodeSymmetryClass(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    if (rel == null || symmClass.getEquivalence() != symm) {
        return enc;
    }
    Thread rep = symmClass.getRepresentative();
    List<Thread> symmThreads = new ArrayList<>(symmClass);
    symmThreads.sort(Comparator.comparingInt(Thread::getId));
    // ===== Construct row =====
    // IMPORTANT: Each thread writes to its own special location for the purpose of starting/terminating threads
    // These need to get skipped.
    Thread t1 = symmThreads.get(0);
    List<Tuple> r1Tuples = new ArrayList<>();
    for (Tuple t : rel.getMaxTupleSet()) {
        Event a = t.getFirst();
        Event b = t.getSecond();
        if (!a.is(Tag.C11.PTHREAD) && !b.is(Tag.C11.PTHREAD) && a.getThread() == t1) {
            r1Tuples.add(t);
        }
    }
    sort(r1Tuples);
    // Construct symmetric rows
    for (int i = 1; i < symmThreads.size(); i++) {
        Thread t2 = symmThreads.get(i);
        Function<Event, Event> p = symm.createTransposition(t1, t2);
        List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
        List<BooleanFormula> r1 = Lists.transform(r1Tuples, t -> rel.getSMTVar(t, ctx));
        List<BooleanFormula> r2 = Lists.transform(r2Tuples, t -> rel.getSMTVar(t, ctx));
        final String id = "_" + rep.getId() + "_" + i;
        // r1 >= r2
        enc = bmgr.and(enc, encodeLexLeader(id, r2, r1, ctx));
        t1 = t2;
        r1Tuples = r2Tuples;
    }
    return enc;
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Thread(com.dat3m.dartagnan.program.Thread) Function(java.util.function.Function) RelationRepository(com.dat3m.dartagnan.wmm.utils.RelationRepository) BREAK_SYMMETRY_BY_SYNC_DEGREE(com.dat3m.dartagnan.configuration.OptionNames.BREAK_SYMMETRY_BY_SYNC_DEGREE) Wmm(com.dat3m.dartagnan.wmm.Wmm) Lists(com.google.common.collect.Lists) Option(org.sosy_lab.common.configuration.Option) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) BREAK_SYMMETRY_ON_RELATION(com.dat3m.dartagnan.configuration.OptionNames.BREAK_SYMMETRY_ON_RELATION) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Configuration(org.sosy_lab.common.configuration.Configuration) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Collectors(java.util.stream.Collectors) 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) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) LogManager(org.apache.logging.log4j.LogManager) Axiom(com.dat3m.dartagnan.wmm.axiom.Axiom) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Thread(com.dat3m.dartagnan.program.Thread) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 2 with EquivalenceClass

use of com.dat3m.dartagnan.utils.equivalence.EquivalenceClass in project Dat3M by hernanponcedeleon.

the class CoSymmetryBreaking method encode.

public BooleanFormula encode(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    if (symmClass.getEquivalence() != symm) {
        return enc;
    }
    Info info = infoMap.get(symmClass);
    if (info == null) {
        logger.warn("Cannot encode co-symmetry because no information has been computed. " + "Make sure that <initialize> gets called before encoding.");
        return enc;
    }
    List<Thread> symmThreads = info.threads;
    // ============= Construct rows =============
    Thread t1 = symmThreads.get(0);
    List<Thread> otherThreads = symmThreads.subList(1, symmThreads.size());
    List<Tuple> r1Tuples = new ArrayList<>();
    for (Store w : info.writes) {
        for (Thread t2 : otherThreads) {
            r1Tuples.add(new Tuple(w, symm.map(w, t2)));
        }
    }
    // Starting row
    List<BooleanFormula> r1 = new ArrayList<>(r1Tuples.size() + 1);
    if (info.hasMustEdges) {
        r1.add(info.writes.get(0).exec());
    }
    r1.addAll(Lists.transform(r1Tuples, t -> co.getSMTVar(t, ctx)));
    // Construct symmetric rows
    Thread rep = symmClass.getRepresentative();
    for (int i = 1; i < symmThreads.size(); i++) {
        Thread t2 = symmThreads.get(i);
        Function<Event, Event> p = symm.createTransposition(t1, t2);
        List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
        List<BooleanFormula> r2 = new ArrayList<>(r2Tuples.size() + 1);
        if (info.hasMustEdges) {
            r2.add(symm.map(info.writes.get(0), t2).exec());
        }
        r2.addAll(Lists.transform(r2Tuples, t -> co.getSMTVar(t, ctx)));
        final String id = "_" + rep.getId() + "_" + i;
        // NOTE: We want to have r1 >= r2 but lexLeader encodes r1 <= r2, so we swap r1 and r2.
        enc = bmgr.and(enc, SymmetryEncoder.encodeLexLeader(id, r2, r1, ctx));
        t1 = t2;
        r1Tuples = r2Tuples;
        r1 = r2;
    }
    return enc;
}
Also used : SymmetryEncoder(com.dat3m.dartagnan.encoding.SymmetryEncoder) java.util(java.util) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Thread(com.dat3m.dartagnan.program.Thread) Function(java.util.function.Function) Lists(com.google.common.collect.Lists) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Store(com.dat3m.dartagnan.program.event.core.Store) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Collectors(java.util.stream.Collectors) Tag(com.dat3m.dartagnan.program.event.Tag) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) RelationNameRepository(com.dat3m.dartagnan.wmm.relation.RelationNameRepository) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) LogManager(org.apache.logging.log4j.LogManager) Axiom(com.dat3m.dartagnan.wmm.axiom.Axiom) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Store(com.dat3m.dartagnan.program.event.core.Store) Thread(com.dat3m.dartagnan.program.Thread) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 3 with EquivalenceClass

use of com.dat3m.dartagnan.utils.equivalence.EquivalenceClass in project Dat3M by hernanponcedeleon.

the class SymmetryReduction method run.

public void run(Program program) {
    ThreadSymmetry symm = ThreadSymmetry.withoutMappings(program);
    Set<? extends EquivalenceClass<Thread>> symmClasses = symm.getNonTrivialClasses();
    if (symmClasses.isEmpty()) {
        return;
    }
    for (EquivalenceClass<Thread> c : symmClasses) {
        Thread rep = c.getRepresentative();
        if (rep.getEvents().stream().noneMatch(x -> x.is(Tag.ASSERTION))) {
            continue;
        }
        rep.setName(rep.getName() + "__symm_unique");
        for (Thread t : c.stream().filter(x -> x != rep).collect(Collectors.toList())) {
            for (Event e : t.getEvents()) {
                if (e.is(Tag.ASSERTION)) {
                    e.getSuccessor().delete();
                    e.delete();
                }
            }
            t.clearCache();
        }
    }
    logger.info("Reduced symmetry of {} many symmetry classes", symmClasses.size());
}
Also used : Tag(com.dat3m.dartagnan.program.event.Tag) EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Logger(org.apache.logging.log4j.Logger) Configuration(org.sosy_lab.common.configuration.Configuration) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) Set(java.util.Set) Thread(com.dat3m.dartagnan.program.Thread) LogManager(org.apache.logging.log4j.LogManager) Collectors(java.util.stream.Collectors) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Event(com.dat3m.dartagnan.program.event.core.Event) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Thread(com.dat3m.dartagnan.program.Thread)

Aggregations

Thread (com.dat3m.dartagnan.program.Thread)3 ThreadSymmetry (com.dat3m.dartagnan.program.analysis.ThreadSymmetry)3 Tag (com.dat3m.dartagnan.program.event.Tag)3 Event (com.dat3m.dartagnan.program.event.core.Event)3 EquivalenceClass (com.dat3m.dartagnan.utils.equivalence.EquivalenceClass)3 Collectors (java.util.stream.Collectors)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Axiom (com.dat3m.dartagnan.wmm.axiom.Axiom)2 Relation (com.dat3m.dartagnan.wmm.relation.Relation)2 RelationNameRepository (com.dat3m.dartagnan.wmm.relation.RelationNameRepository)2 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)2 Preconditions (com.google.common.base.Preconditions)2 Lists (com.google.common.collect.Lists)2 java.util (java.util)2 Function (java.util.function.Function)2 Configuration (org.sosy_lab.common.configuration.Configuration)2 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)2 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)2 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)2