Search in sources :

Example 16 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class RMWGraph method repopulate.

/* Right now there are four cases where the RMW-Relation is established:
     (1) LOCK : Load -> CondJump -> Store
     (2) RMW : RMWLoad -> RMWStore (completely static)
     (3) ExclAccess : ExclLoad -> ExclStore (dependent on control flow)
     (4) Atomic blocks: BeginAtomic -> Events* -> EndAtomic

     We need to keep this in line with the implementation of RelRMW!
    */
@Override
public void repopulate() {
    // Atomic blocks
    model.getAtomicBlocksMap().values().stream().flatMap(Collection::stream).forEach(block -> {
        for (int i = 0; i < block.size(); i++) {
            for (int j = i + 1; j < block.size(); j++) {
                simpleGraph.add(new Edge(block.get(i).getId(), block.get(j).getId()));
            }
        }
    });
    for (List<EventData> events : model.getThreadEventsMap().values()) {
        EventData lastExclLoad = null;
        for (int i = 0; i < events.size(); i++) {
            EventData e = events.get(i);
            if (e.isRead()) {
                if (e.isLock()) {
                    // Locks ~ (Load -> CondJump -> Store)
                    if (i + 1 < events.size()) {
                        // The condition fails, if the lock was not obtained cause then
                        // it will be the last event of the thread (we terminate on failed locks)
                        EventData next = events.get(i + 1);
                        simpleGraph.add(new Edge(e.getId(), next.getId()));
                    }
                } else if (e.isExclusive()) {
                    // LoadExcl
                    lastExclLoad = e;
                }
            } else if (e.isWrite()) {
                if (e.isExclusive()) {
                    // StoreExcl
                    if (lastExclLoad == null) {
                        throw new IllegalStateException("Exclusive store was executed without preceding exclusive load.");
                    }
                    simpleGraph.add(new Edge(lastExclLoad.getId(), e.getId()));
                    lastExclLoad = null;
                } else if (e.getEvent() instanceof RMWStore) {
                    // RMWStore
                    EventData load = model.getData(((RMWStore) e.getEvent()).getLoadEvent()).get();
                    simpleGraph.add(new Edge(load.getId(), e.getId()));
                }
            }
        }
    }
}
Also used : RMWStore(com.dat3m.dartagnan.program.event.core.rmw.RMWStore) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EventData(com.dat3m.dartagnan.verification.model.EventData)

Example 17 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class RcuGraph method edgeStream.

@Override
public Stream<Edge> edgeStream(int id, EdgeDirection dir) {
    EventData e = getEvent(id);
    BiMap<EventData, EventData> map = (dir == EdgeDirection.OUTGOING ? lockUnlockMap : unlockLockMap);
    EventData a = (dir == EdgeDirection.OUTGOING ? e : map.get(e));
    EventData b = (a == e ? map.get(e) : e);
    return (a != null && b != null) ? Stream.of(new Edge(a.getId(), b.getId())) : Stream.empty();
}
Also used : Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EventData(com.dat3m.dartagnan.verification.model.EventData)

Example 18 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class StaticDefaultWMMGraph method getEdgeFromTuple.

private Edge getEdgeFromTuple(Tuple t) {
    Optional<EventData> e1 = model.getData(t.getFirst());
    Optional<EventData> e2 = model.getData(t.getSecond());
    return (e1.isPresent() && e2.isPresent()) ? new Edge(e1.get().getId(), e2.get().getId()) : null;
}
Also used : Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EventData(com.dat3m.dartagnan.verification.model.EventData)

Example 19 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class CoreReasoner method toCoreReason.

public Conjunction<CoreLiteral> toCoreReason(Conjunction<CAATLiteral> baseReason) {
    RelationRepository repo = memoryModel.getRelationRepository();
    EventDomain domain = executionGraph.getDomain();
    List<CoreLiteral> coreReason = new ArrayList<>(baseReason.getSize());
    for (CAATLiteral lit : baseReason.getLiterals()) {
        if (lit instanceof ElementLiteral) {
            Event e = domain.getObjectById(((ElementLiteral) lit).getElement().getId()).getEvent();
            // We only have static tags, so all of them reduce to execution literals
            coreReason.add(new ExecLiteral(e, lit.isNegative()));
        } else {
            EdgeLiteral edgeLit = (EdgeLiteral) lit;
            Edge edge = edgeLit.getEdge();
            Event e1 = domain.getObjectById(edge.getFirst()).getEvent();
            Event e2 = domain.getObjectById(edge.getSecond()).getEvent();
            Tuple tuple = new Tuple(e1, e2);
            Relation rel = repo.getRelation(lit.getName());
            if (lit.isPositive() && rel.getMinTupleSet().contains(tuple)) {
                // Statically present edges
                addExecReason(tuple, coreReason);
            } else if (lit.isNegative() && !rel.getMaxTupleSet().contains(tuple)) {
            // Statically absent edges
            } else {
                if (rel instanceof RelFencerel) {
                    // We should do this transformation directly on the Wmm to avoid this special reasoning
                    if (lit.isNegative()) {
                        throw new UnsupportedOperationException(String.format("FenceRel %s is not allowed on the rhs of differences.", rel));
                    }
                    addFenceReason(rel, edge, coreReason);
                } else if (rel.getName().equals(LOC)) {
                    coreReason.add(new AddressLiteral(tuple, lit.isNegative()));
                } else if (rel.getName().equals(RF) || rel.getName().equals(CO)) {
                    coreReason.add(new RelLiteral(rel.getName(), tuple, lit.isNegative()));
                } else {
                    // TODO: Right now, we assume many relations like Data, Ctrl and Addr to be
                    // static.
                    addExecReason(tuple, coreReason);
                }
            }
        }
    }
    minimize(coreReason);
    return new Conjunction<>(coreReason);
}
Also used : CAATLiteral(com.dat3m.dartagnan.solver.caat.reasoning.CAATLiteral) ArrayList(java.util.ArrayList) RelationRepository(com.dat3m.dartagnan.wmm.utils.RelationRepository) Relation(com.dat3m.dartagnan.wmm.relation.Relation) EventDomain(com.dat3m.dartagnan.solver.caat4wmm.EventDomain) ElementLiteral(com.dat3m.dartagnan.solver.caat.reasoning.ElementLiteral) RelFencerel(com.dat3m.dartagnan.wmm.relation.base.stat.RelFencerel) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) Event(com.dat3m.dartagnan.program.event.core.Event) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EdgeLiteral(com.dat3m.dartagnan.solver.caat.reasoning.EdgeLiteral) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 20 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class TransitiveGraph method updateEdge.

// Every (transitive) edge that gets added by adding <edge> is collected into <addedEdged>
private void updateEdge(Edge edge, Collection<Edge> addedEdges) {
    if (!simpleGraph.add(edge)) {
        return;
    }
    addedEdges.add(edge);
    final int time = edge.getTime();
    for (Edge inEdge : inEdges(edge.getFirst())) {
        Edge newEdge = combine(inEdge, edge, time);
        if (simpleGraph.add(newEdge)) {
            addedEdges.add(newEdge);
            for (Edge outEdge : outEdges(edge.getSecond())) {
                Edge combined = combine(newEdge, outEdge, time);
                if (simpleGraph.add(combined)) {
                    addedEdges.add(combined);
                }
            }
        }
    }
    for (Edge outEdge : outEdges(edge.getSecond())) {
        Edge newEdge = combine(edge, outEdge, time);
        if (simpleGraph.add(newEdge)) {
            addedEdges.add(newEdge);
        }
    }
}
Also used : Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Aggregations

Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)22 EventData (com.dat3m.dartagnan.verification.model.EventData)10 EdgeDirection (com.dat3m.dartagnan.solver.caat.misc.EdgeDirection)7 Stream (java.util.stream.Stream)6 java.util (java.util)5 Function (java.util.function.Function)5 Thread (com.dat3m.dartagnan.program.Thread)3 BigInteger (java.math.BigInteger)3 RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)2 Element (com.dat3m.dartagnan.solver.caat.predicates.sets.Element)2 Conjunction (com.dat3m.dartagnan.utils.logic.Conjunction)2 Iterators (com.google.common.collect.Iterators)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Spliterator (java.util.Spliterator)2 IntStream (java.util.stream.IntStream)2 StreamSupport (java.util.stream.StreamSupport)2 Event (com.dat3m.dartagnan.program.event.core.Event)1 RMWStore (com.dat3m.dartagnan.program.event.core.rmw.RMWStore)1