Search in sources :

Example 1 with ExecutionAnalysis

use of com.dat3m.dartagnan.program.analysis.ExecutionAnalysis in project Dat3M by hernanponcedeleon.

the class Acyclic method reduceWithMinSets.

private void reduceWithMinSets(TupleSet encodeSet) {
    /*
            ASSUMPTION: MinSet is acyclic!
            IDEA:
                Edges that are (must-)transitively implied do not need to get encoded.
                For this, we compute a (must-)transitive closure and a (must-)transitive reduction of must(rel).
                The difference "must(rel)+ \ red(must(rel))" does not net to be encoded.
                Note that it this is sound if the closure gets underapproximated and/or the reduction
                gets over approximated.
            COMPUTATION:
                (1) We compute an approximate (must-)transitive closure of must(rel)
                    - must(rel) is likely to be already transitive per thread (due to mostly coming from po)
                      Hence, we get a reasonable approximation by closing transitively over thread-crossing edges only.
                (2) We compute a (must) transitive reduction of the transitively closed must(rel)+.
                    - Since must(rel)+ is transitive, it suffice to check for each edge (a, c) if there
                      is an intermediate event b such that (a, b) and (b, c) are in must(rel)+
                      and b is implied by either a or c.
                    - It is possible to reduce must(rel) but that may give a less precise result.
         */
    ExecutionAnalysis exec = analysisContext.get(ExecutionAnalysis.class);
    TupleSet minSet = rel.getMinTupleSet();
    // (1) Approximate transitive closure of minSet (only gets computed when crossEdges are available)
    List<Tuple> crossEdges = minSet.stream().filter(t -> t.isCrossThread() && !t.getFirst().is(Tag.INIT)).collect(Collectors.toList());
    TupleSet transMinSet = crossEdges.isEmpty() ? minSet : new TupleSet(minSet);
    for (Tuple crossEdge : crossEdges) {
        Event e1 = crossEdge.getFirst();
        Event e2 = crossEdge.getSecond();
        List<Event> ingoing = new ArrayList<>();
        // ingoing events + self
        ingoing.add(e1);
        minSet.getBySecond(e1).stream().map(Tuple::getFirst).filter(e -> exec.isImplied(e, e1)).forEach(ingoing::add);
        List<Event> outgoing = new ArrayList<>();
        // outgoing edges + self
        outgoing.add(e2);
        minSet.getByFirst(e2).stream().map(Tuple::getSecond).filter(e -> exec.isImplied(e, e2)).forEach(outgoing::add);
        for (Event in : ingoing) {
            for (Event out : outgoing) {
                transMinSet.add(new Tuple(in, out));
            }
        }
    }
    // (2) Approximate reduction of transitive must-set: red(must(r)+).
    // Note: We reduce the transitive closure which may have more edges
    // that can be used to perform reduction
    TupleSet reduct = TupleSet.approximateTransitiveMustReduction(exec, transMinSet);
    // Remove (must(r)+ \ red(must(r)+)
    encodeSet.removeIf(t -> transMinSet.contains(t) && !reduct.contains(t));
}
Also used : Utils(com.dat3m.dartagnan.wmm.utils.Utils) java.util(java.util) 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) Collectors(java.util.stream.Collectors) Tag(com.dat3m.dartagnan.program.event.Tag) DependencyGraph(com.dat3m.dartagnan.utils.dependable.DependencyGraph) Logger(org.apache.logging.log4j.Logger) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) GlobalSettings(com.dat3m.dartagnan.GlobalSettings) LogManager(org.apache.logging.log4j.LogManager) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 2 with ExecutionAnalysis

use of com.dat3m.dartagnan.program.analysis.ExecutionAnalysis 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 3 with ExecutionAnalysis

use of com.dat3m.dartagnan.program.analysis.ExecutionAnalysis 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 4 with ExecutionAnalysis

use of com.dat3m.dartagnan.program.analysis.ExecutionAnalysis in project Dat3M by hernanponcedeleon.

the class RelDomainIdentity method getMinTupleSet.

@Override
public TupleSet getMinTupleSet() {
    if (minTupleSet == null) {
        ExecutionAnalysis exec = analysisContext.get(ExecutionAnalysis.class);
        minTupleSet = new TupleSet();
        r1.getMinTupleSet().stream().filter(t -> exec.isImplied(t.getFirst(), t.getSecond())).map(t -> new Tuple(t.getFirst(), t.getFirst())).forEach(minTupleSet::add);
    }
    return minTupleSet;
}
Also used : BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Sets(com.google.common.collect.Sets) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 5 with ExecutionAnalysis

use of com.dat3m.dartagnan.program.analysis.ExecutionAnalysis in project Dat3M by hernanponcedeleon.

the class RelRangeIdentity method getMinTupleSet.

@Override
public TupleSet getMinTupleSet() {
    if (minTupleSet == null) {
        ExecutionAnalysis exec = analysisContext.get(ExecutionAnalysis.class);
        minTupleSet = new TupleSet();
        r1.getMinTupleSet().stream().filter(t -> exec.isImplied(t.getSecond(), t.getFirst())).map(t -> new Tuple(t.getSecond(), t.getSecond())).forEach(minTupleSet::add);
    }
    return minTupleSet;
}
Also used : BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Sets(com.google.common.collect.Sets) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Aggregations

ExecutionAnalysis (com.dat3m.dartagnan.program.analysis.ExecutionAnalysis)14 Event (com.dat3m.dartagnan.program.event.core.Event)13 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)11 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)11 Relation (com.dat3m.dartagnan.wmm.relation.Relation)8 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)7 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)7 SolverContext (org.sosy_lab.java_smt.api.SolverContext)7 Sets (com.google.common.collect.Sets)6 Set (java.util.Set)5 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)2 Tag (com.dat3m.dartagnan.program.event.Tag)2 Load (com.dat3m.dartagnan.program.event.core.Load)2 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)2 Store (com.dat3m.dartagnan.program.event.core.Store)2 EndAtomic (com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic)2 FilterAbstract (com.dat3m.dartagnan.program.filter.FilterAbstract)2 java.util (java.util)2