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()));
}
}
}
}
}
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();
}
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;
}
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);
}
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);
}
}
}
Aggregations