use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ThreadSymmetry method createMappings.
private void createMappings() {
for (Thread thread : program.getThreads()) {
Map<Integer, Event> mapping = symmMap.computeIfAbsent(thread, key -> new HashMap<>());
thread.getEvents().forEach(e -> mapping.put(e.getFId(), e));
}
Set<? extends EquivalenceClass<Thread>> classes = getAllEquivalenceClasses();
for (EquivalenceClass<Thread> clazz : classes) {
int size = symmMap.get(clazz.getRepresentative()).size();
for (Thread t : clazz) {
if (symmMap.get(t).size() == size) {
Verify.verify(symmMap.get(t).size() == size, "Symmetric threads T%s and T%s have different number of events: %s vs. %s", clazz.getRepresentative(), t, size, symmMap.get(t).size());
}
}
}
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class EndAtomic method runLocalAnalysis.
@Override
public void runLocalAnalysis(Program program, Context context) {
// ===== Temporary fix to rematch atomic blocks correctly =====
BranchEquivalence eq = context.requires(BranchEquivalence.class);
List<Event> begins = this.thread.getEvents().stream().filter(x -> x instanceof BeginAtomic && eq.isReachableFrom(x, this)).collect(Collectors.toList());
this.begin = (BeginAtomic) begins.get(begins.size() - 1);
// =======================================================
findEnclosedEvents(eq);
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class Relation method getExecPair.
protected BooleanFormula getExecPair(Event e1, Event e2, SolverContext ctx) {
if (e1.exec() == e2.exec()) {
return e1.exec();
}
if (e1.getCId() > e2.getCId()) {
Event temp = e1;
e1 = e2;
e2 = temp;
}
ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
if (exec.isImplied(e1, e2)) {
return e1.exec();
} else if (exec.isImplied(e2, e1)) {
return e2.exec();
}
return ctx.getFormulaManager().getBooleanFormulaManager().and(e1.exec(), e2.exec());
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class BasicRegRelation method doEncodeApprox.
BooleanFormula doEncodeApprox(Collection<Event> regReaders, SolverContext ctx) {
FormulaManager fmgr = ctx.getFormulaManager();
BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
for (Event regReader : regReaders) {
Set<Tuple> writerReaders = maxTupleSet.getBySecond(regReader);
for (Register register : getRegisters(regReader)) {
List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
List<Event> possibleWriters = writers.stream().filter(x -> writerReaders.contains(new Tuple(x, regReader))).collect(Collectors.toList());
if (writers.isEmpty() || writers.get(0).getCId() >= regReader.getCId()) {
BooleanFormula equal = generalEqual(register.toIntFormula(regReader, ctx), new IValue(BigInteger.ZERO, register.getPrecision()).toIntFormula(ctx), ctx);
enc = bmgr.and(enc, equal);
} else {
for (int i = 0; i < possibleWriters.size(); i++) {
Event regWriter = possibleWriters.get(i);
// RegReader uses the value of RegWriter if it is executed ..
BooleanFormula clause = getExecPair(regWriter, regReader, ctx);
BooleanFormula edge = this.getSMTVar(regWriter, regReader, ctx);
// .. and no other write to the same register is executed in between
for (int j = i + 1; j < possibleWriters.size(); j++) {
clause = bmgr.and(clause, bmgr.not(possibleWriters.get(j).exec()));
}
// Encode edge and value binding
enc = bmgr.and(enc, bmgr.equivalence(edge, clause));
BooleanFormula equal = generalEqual(((RegWriter) regWriter).getResultRegisterExpr(), register.toIntFormula(regReader, ctx), ctx);
enc = bmgr.and(enc, bmgr.implication(edge, equal));
}
}
}
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.Event 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));
}
}
}
}
Aggregations