Search in sources :

Example 21 with Event

use of com.dat3m.dartagnan.program.event.core.Event 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)

Example 22 with Event

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

the class RelRf method atomicBlockOptimization.

private void atomicBlockOptimization() {
    // TODO: This function can not only reduce rf-edges
    // but we could also figure out implied coherences:
    // Assume w1 and w2 are aliasing in the same block and w1 is before w2,
    // then if w1 is co-before some external w3, then so is w2, i.e.
    // co(w1, w3) => co(w2, w3), but we also have co(w2, w3) => co(w1, w3)
    // so co(w1, w3) <=> co(w2, w3).
    // This information is not expressible in terms of min/must sets, but
    // we could still encode it.
    int sizeBefore = maxTupleSet.size();
    // Atomics blocks: BeginAtomic -> EndAtomic
    ExecutionAnalysis exec = analysisContext.get(ExecutionAnalysis.class);
    AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
    FilterAbstract filter = FilterIntersection.get(FilterBasic.get(RMW), FilterBasic.get(SVCOMP.SVCOMPATOMIC));
    for (Event end : task.getProgram().getCache().getEvents(filter)) {
        // Collect memEvents of the atomic block
        List<Store> writes = new ArrayList<>();
        List<Load> reads = new ArrayList<>();
        EndAtomic endAtomic = (EndAtomic) end;
        for (Event b : endAtomic.getBlock()) {
            if (b instanceof Load) {
                reads.add((Load) b);
            } else if (b instanceof Store) {
                writes.add((Store) b);
            }
        }
        for (Load r : reads) {
            // If there is any write w inside the atomic block that is guaranteed to
            // execute before the read and that aliases with it,
            // then the read won't be able to read any external writes
            boolean hasImpliedWrites = writes.stream().anyMatch(w -> w.getCId() < r.getCId() && exec.isImplied(r, w) && alias.mustAlias(r, w));
            if (hasImpliedWrites) {
                maxTupleSet.removeIf(t -> t.getSecond() == r && t.isCrossThread());
            }
        }
    }
    logger.info("Atomic block optimization eliminated " + (sizeBefore - maxTupleSet.size()) + " reads");
}
Also used : Load(com.dat3m.dartagnan.program.event.core.Load) EndAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) FilterAbstract(com.dat3m.dartagnan.program.filter.FilterAbstract) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) Store(com.dat3m.dartagnan.program.event.core.Store) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis)

Example 23 with Event

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

the class RelRf method applyLocalConsistency.

private void applyLocalConsistency() {
    // Remove future reads
    maxTupleSet.removeIf(Tuple::isBackward);
    // Remove past reads
    ExecutionAnalysis exec = analysisContext.get(ExecutionAnalysis.class);
    AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
    Set<Tuple> deletedTuples = new HashSet<>();
    for (Event r : task.getProgram().getCache().getEvents(FilterBasic.get(READ))) {
        MemEvent read = (MemEvent) r;
        // The set of same-thread writes as well as init writes that could be read from (all before the read)
        // sorted by order (init events first)
        List<MemEvent> possibleWrites = maxTupleSet.getBySecond(read).stream().map(Tuple::getFirst).filter(e -> (e.getThread() == read.getThread() || e.is(INIT))).map(x -> (MemEvent) x).sorted((o1, o2) -> o1.is(INIT) == o2.is(INIT) ? (o1.getCId() - o2.getCId()) : o1.is(INIT) ? -1 : 1).collect(Collectors.toList());
        // The set of writes that won't be readable due getting overwritten.
        Set<MemEvent> deletedWrites = new HashSet<>();
        // - w2 must alias with either w1 or r.
        for (int i = 0; i < possibleWrites.size(); i++) {
            MemEvent w1 = possibleWrites.get(i);
            for (MemEvent w2 : possibleWrites.subList(i + 1, possibleWrites.size())) {
                // executed
                if ((exec.isImplied(w1, w2) || exec.isImplied(read, w2)) && (alias.mustAlias(w1, w2) || alias.mustAlias(w2, read))) {
                    deletedWrites.add(w1);
                    break;
                }
            }
        }
        for (Event w : deletedWrites) {
            deletedTuples.add(new Tuple(w, read));
        }
    }
    maxTupleSet.removeAll(deletedTuples);
}
Also used : AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) java.util(java.util) BooleanType(org.sosy_lab.java_smt.api.FormulaType.BooleanType) Store(com.dat3m.dartagnan.program.event.core.Store) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) org.sosy_lab.java_smt.api(org.sosy_lab.java_smt.api) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Utils(com.dat3m.dartagnan.expression.utils.Utils) RF(com.dat3m.dartagnan.wmm.relation.RelationNameRepository.RF) Collectors(java.util.stream.Collectors) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) FilterAbstract(com.dat3m.dartagnan.program.filter.FilterAbstract) Tag(com.dat3m.dartagnan.program.event.Tag) EndAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic) WmmAnalysis(com.dat3m.dartagnan.wmm.analysis.WmmAnalysis) Logger(org.apache.logging.log4j.Logger) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) FilterIntersection(com.dat3m.dartagnan.program.filter.FilterIntersection) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) Load(com.dat3m.dartagnan.program.event.core.Load) LogManager(org.apache.logging.log4j.LogManager) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) 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)

Example 24 with Event

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

the class RelExt method getMaxTupleSet.

@Override
public TupleSet getMaxTupleSet() {
    if (maxTupleSet == null) {
        maxTupleSet = new TupleSet();
        List<Thread> threads = task.getProgram().getThreads();
        for (int i = 0; i < threads.size(); i++) {
            Thread t1 = threads.get(i);
            for (int j = i + 1; j < threads.size(); j++) {
                Thread t2 = threads.get(j);
                for (Event e1 : t1.getCache().getEvents(FilterBasic.get(Tag.VISIBLE))) {
                    for (Event e2 : t2.getCache().getEvents(FilterBasic.get(Tag.VISIBLE))) {
                        maxTupleSet.add(new Tuple(e1, e2));
                        maxTupleSet.add(new Tuple(e2, e1));
                    }
                }
            }
        }
    }
    return maxTupleSet;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) Thread(com.dat3m.dartagnan.program.Thread)

Example 25 with Event

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

the class RelDomainIdentity method encodeApprox.

@Override
protected BooleanFormula encodeApprox(SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    for (Tuple tuple1 : encodeTupleSet) {
        Event e = tuple1.getFirst();
        BooleanFormula opt = bmgr.makeFalse();
        // TODO: Optimize using minSets (but no CAT uses this anyway)
        for (Tuple tuple2 : r1.getMaxTupleSet().getByFirst(e)) {
            opt = bmgr.or(r1.getSMTVar(e, tuple2.getSecond(), ctx));
        }
        enc = bmgr.and(enc, bmgr.equivalence(this.getSMTVar(e, e, ctx), opt));
    }
    return enc;
}
Also used : BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) 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