use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class LoopUnrolling method unrollThreadOnce.
private void unrollThreadOnce(Thread t, int bound) {
// NOTE: The implemented unroll semantics are identical to the previous one we had.
// TODO: We might want to allow usage of different bounds per loop by e.g.
// annotating the looping jump with a custom bound counter
// TODO (2): The code can surely be cleaned up somehow
Event cur = t.getEntry();
Event successor;
Event predecessor = null;
Event newPred;
do {
successor = cur.getSuccessor();
if (cur instanceof CondJump && ((CondJump) cur).getLabel().getOId() < cur.getOId()) {
CondJump jump = (CondJump) cur;
Label label = jump.getLabel();
if (bound > 1) {
predecessor = copyPath(label, successor, predecessor);
}
if (bound == 1) {
Label target = (Label) jump.getThread().getExit();
newPred = EventFactory.newGoto(target);
newPred.addFilters(Tag.BOUND);
predecessor.setSuccessor(newPred);
} else {
newPred = predecessor;
}
} else {
newPred = cur;
if (predecessor != null) {
// TODO: Is this needed anymore since we got rid of If events?
if (bound != 1) {
newPred = cur.getCopy();
}
predecessor.setSuccessor(newPred);
}
}
cur = successor;
predecessor = newPred;
} while (successor != null);
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class LoopUnrolling method copyPath.
private Event copyPath(Event from, Event until, Event appendTo) {
while (from != null && !from.equals(until)) {
Event copy = from.getCopy();
appendTo.setSuccessor(copy);
appendTo = copy;
from = from.getSuccessor();
}
return appendTo;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeThreadCF.
private BooleanFormula encodeThreadCF(Thread thread, SolverContext ctx) {
checkInitialized();
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
BiFunction<BooleanFormula, BooleanFormula, BooleanFormula> cfEncoder = shouldAllowPartialExecutions ? bmgr::implication : bmgr::equivalence;
Map<Label, Set<Event>> labelJumpMap = new HashMap<>();
Event pred = null;
for (Event e : thread.getEntry().getSuccessors()) {
// Immediate control flow
BooleanFormula cfCond = pred == null ? bmgr.makeTrue() : pred.cf();
if (pred instanceof CondJump) {
CondJump jump = (CondJump) pred;
cfCond = bmgr.and(cfCond, bmgr.not(jump.getGuard().toBoolFormula(jump, ctx)));
// NOTE: we need to register the actual jumps here, because the
// listener sets of labels is too large (it contains old copies)
labelJumpMap.computeIfAbsent(jump.getLabel(), key -> new HashSet<>()).add(jump);
}
// Control flow via jumps
if (e instanceof Label) {
for (Event jump : labelJumpMap.getOrDefault(e, Collections.emptySet())) {
CondJump j = (CondJump) jump;
cfCond = bmgr.or(cfCond, bmgr.and(j.cf(), j.getGuard().toBoolFormula(j, ctx)));
}
}
enc = bmgr.and(enc, cfEncoder.apply(e.cf(), cfCond), e.encodeExec(ctx));
pred = e;
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeDependencies.
/**
* @param ctx
* Builder of expressions and formulas.
* @return
* Describes that for each pair of events, if the reader uses the result of the writer,
* then the value the reader gets from the register is exactly the value that the writer computed.
* Also, the reader may only use the value of the latest writer that is executed.
* Also, if no fitting writer is executed, the reader uses 0.
*/
public BooleanFormula encodeDependencies(SolverContext ctx) {
logger.info("Encoding dependencies");
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
for (Map.Entry<Event, Map<Register, Dependency.State>> e : dep.getAll()) {
Event reader = e.getKey();
for (Map.Entry<Register, Dependency.State> r : e.getValue().entrySet()) {
Formula value = r.getKey().toIntFormula(reader, ctx);
Dependency.State state = r.getValue();
BooleanFormula overwrite = bmgr.makeFalse();
for (Event writer : reverse(state.may)) {
assert writer instanceof RegWriter;
BooleanFormula edge;
if (state.must.contains(writer)) {
edge = writer.exec();
} else {
edge = dependencyEdgeVariable(writer, reader, bmgr);
enc = bmgr.and(enc, bmgr.equivalence(edge, bmgr.and(writer.exec(), reader.cf(), bmgr.not(overwrite))));
}
enc = bmgr.and(enc, bmgr.implication(edge, generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx)));
overwrite = bmgr.or(overwrite, writer.exec());
}
if (initializeRegisters && !state.initialized) {
enc = bmgr.and(enc, bmgr.or(overwrite, bmgr.not(reader.cf()), generalEqualZero(value, ctx)));
}
}
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class SymmetryEncoder method encodeSymmetryClass.
public BooleanFormula encodeSymmetryClass(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
if (rel == null || symmClass.getEquivalence() != symm) {
return enc;
}
Thread rep = symmClass.getRepresentative();
List<Thread> symmThreads = new ArrayList<>(symmClass);
symmThreads.sort(Comparator.comparingInt(Thread::getId));
// ===== Construct row =====
// IMPORTANT: Each thread writes to its own special location for the purpose of starting/terminating threads
// These need to get skipped.
Thread t1 = symmThreads.get(0);
List<Tuple> r1Tuples = new ArrayList<>();
for (Tuple t : rel.getMaxTupleSet()) {
Event a = t.getFirst();
Event b = t.getSecond();
if (!a.is(Tag.C11.PTHREAD) && !b.is(Tag.C11.PTHREAD) && a.getThread() == t1) {
r1Tuples.add(t);
}
}
sort(r1Tuples);
// Construct symmetric rows
for (int i = 1; i < symmThreads.size(); i++) {
Thread t2 = symmThreads.get(i);
Function<Event, Event> p = symm.createTransposition(t1, t2);
List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
List<BooleanFormula> r1 = Lists.transform(r1Tuples, t -> rel.getSMTVar(t, ctx));
List<BooleanFormula> r2 = Lists.transform(r2Tuples, t -> rel.getSMTVar(t, ctx));
final String id = "_" + rep.getId() + "_" + i;
// r1 >= r2
enc = bmgr.and(enc, encodeLexLeader(id, r2, r1, ctx));
t1 = t2;
r1Tuples = r2Tuples;
}
return enc;
}
Aggregations