use of com.dat3m.dartagnan.program.event.core.Store in project Dat3M by hernanponcedeleon.
the class CoSymmetryBreaking method initialize.
private void initialize(EquivalenceClass<Thread> symmClass) {
Info info = new Info();
infoMap.put(symmClass, info);
// Get symmetric threads and order them by tid
List<Thread> symmThreads = new ArrayList<>(symmClass);
symmThreads.sort(Comparator.comparingInt(Thread::getId));
info.threads = symmThreads;
// Get stores of first thread
List<Store> writes = symmThreads.get(0).getCache().getEvents(FilterBasic.get(Tag.WRITE)).stream().map(Store.class::cast).collect(Collectors.toList());
// Symmetric writes that cannot alias are related to e.g. thread-creation
// We do not want to break on those
writes.removeIf(w -> !alias.mayAlias(w, (Store) symm.map(w, symmThreads.get(1))));
// We compute the (overall) sync-degree of a write w as the maximal sync degree over all
// axioms. The sync-degree of w for axiom(r) is computed via must(r).
List<Axiom> axioms = task.getAxioms();
Map<Store, Integer> syncDegreeMap = new HashMap<>(writes.size());
for (Store w : writes) {
int syncDeg = 0;
for (Axiom ax : axioms) {
TupleSet minSet = ax.getRelation().getMinTupleSet();
syncDeg = Math.max(syncDeg, (1 + minSet.getBySecond(w).size()) * (1 + minSet.getByFirst(w).size()));
}
syncDegreeMap.put(w, syncDeg);
}
// Sort the writes by sync-degree (highest first).
// This will be the order in which we break coherences!
Comparator<Store> breakingOrder = Comparator.<Store>comparingInt(syncDegreeMap::get).reversed();
writes.sort(breakingOrder);
// first position.
for (int i = 0; i < writes.size(); i++) {
Store w = writes.get(i);
boolean mustAlias = symmThreads.stream().allMatch(t -> alias.mustAlias(w, (Store) symm.map(w, t)));
if (mustAlias) {
info.hasMustEdges = true;
// Move entry to front
writes.add(0, writes.remove(i));
break;
}
}
info.writes = writes;
}
Aggregations