use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.
the class RelMinus method encodeApprox.
@Override
protected BooleanFormula encodeApprox(SolverContext ctx) {
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
TupleSet min = getMinTupleSet();
for (Tuple tuple : encodeTupleSet) {
if (min.contains(tuple)) {
enc = bmgr.and(enc, bmgr.equivalence(this.getSMTVar(tuple, ctx), getExecPair(tuple, ctx)));
continue;
}
BooleanFormula opt1 = r1.getSMTVar(tuple, ctx);
BooleanFormula opt2 = bmgr.not(r2.getSMTVar(tuple, ctx));
if (Relation.PostFixApprox) {
enc = bmgr.and(enc, bmgr.implication(bmgr.and(opt1, opt2), this.getSMTVar(tuple, ctx)));
} else {
enc = bmgr.and(enc, bmgr.equivalence(this.getSMTVar(tuple, ctx), bmgr.and(opt1, opt2)));
}
}
return enc;
}
use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.
the class BasicRegRelation method mkTupleSets.
void mkTupleSets(Collection<Event> regReaders) {
maxTupleSet = new TupleSet();
minTupleSet = new TupleSet();
ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
for (Event regReader : regReaders) {
for (Register register : getRegisters(regReader)) {
List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
// =============== Reduce set of writes ==================
// TODO: We assume that any Register-Write is always executed
// if it is contained in the program flow
// This may fail for RMWReadCond?! It seems to work fine for the litmus tests though.
// =========================
List<Event> possibleWriters = writers.stream().filter(x -> x.getCId() < regReader.getCId() && !exec.areMutuallyExclusive(x, regReader)).collect(Collectors.toList());
List<Event> impliedWriters = possibleWriters.stream().filter(x -> exec.isImplied(regReader, x)).collect(Collectors.toList());
if (!impliedWriters.isEmpty()) {
Event lastImplied = impliedWriters.get(impliedWriters.size() - 1);
possibleWriters.removeIf(x -> x.getCId() < lastImplied.getCId());
}
possibleWriters.removeIf(x -> possibleWriters.stream().anyMatch(y -> x.getCId() < y.getCId() && exec.isImplied(x, y)));
// --- Min sets ---
if (possibleWriters.size() == 1) {
// there is only a single regWriter
minTupleSet.add(new Tuple(possibleWriters.stream().findAny().get(), regReader));
} else {
// there are multiple regWriters, but some are exclusive to all others
for (Event writer : possibleWriters) {
if (possibleWriters.stream().allMatch(x -> x == writer || exec.areMutuallyExclusive(x, writer))) {
minTupleSet.add(new Tuple(writer, regReader));
}
}
}
// --- Max sets ---
for (Event regWriter : possibleWriters) {
maxTupleSet.add(new Tuple(regWriter, regReader));
}
}
}
}
use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.
the class RelCo method getMaxTupleSet.
@Override
public TupleSet getMaxTupleSet() {
if (maxTupleSet == null) {
logger.info("Computing maxTupleSet for " + getName());
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
maxTupleSet = new TupleSet();
List<Event> eventsInit = task.getProgram().getCache().getEvents(FilterBasic.get(INIT));
List<Event> eventsStore = task.getProgram().getCache().getEvents(FilterMinus.get(FilterBasic.get(WRITE), FilterBasic.get(INIT)));
for (Event e1 : eventsInit) {
for (Event e2 : eventsStore) {
if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
maxTupleSet.add(new Tuple(e1, e2));
}
}
}
for (Event e1 : eventsStore) {
for (Event e2 : eventsStore) {
if (e1.getCId() != e2.getCId() && alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
maxTupleSet.add(new Tuple(e1, e2));
}
}
}
removeMutuallyExclusiveTuples(maxTupleSet);
if (wmmAnalysis.isLocallyConsistent()) {
applyLocalConsistencyMaxSet();
}
logger.info("maxTupleSet size for " + getName() + ": " + maxTupleSet.size());
}
return maxTupleSet;
}
use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.
the class RelLoc method getMinTupleSet.
@Override
public TupleSet getMinTupleSet() {
if (minTupleSet == null) {
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
minTupleSet = new TupleSet();
for (Tuple t : getMaxTupleSet()) {
if (alias.mustAlias((MemEvent) t.getFirst(), (MemEvent) t.getSecond())) {
minTupleSet.add(t);
}
}
}
return minTupleSet;
}
use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.
the class RelRf method getMaxTupleSet.
@Override
public TupleSet getMaxTupleSet() {
if (maxTupleSet == null) {
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
logger.info("Computing maxTupleSet for " + getName());
maxTupleSet = new TupleSet();
List<Event> loadEvents = task.getProgram().getCache().getEvents(FilterBasic.get(READ));
List<Event> storeEvents = task.getProgram().getCache().getEvents(FilterBasic.get(WRITE));
for (Event e1 : storeEvents) {
for (Event e2 : loadEvents) {
if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
maxTupleSet.add(new Tuple(e1, e2));
}
}
}
removeMutuallyExclusiveTuples(maxTupleSet);
if (wmmAnalysis.isLocallyConsistent()) {
applyLocalConsistency();
}
if (wmmAnalysis.doesRespectAtomicBlocks()) {
atomicBlockOptimization();
}
logger.info("maxTupleSet size for " + getName() + ": " + maxTupleSet.size());
}
return maxTupleSet;
}
Aggregations