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