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